diff --git a/.gitignore b/.gitignore index 5875e07..44a1b60 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ test/version_tmp tmp .tmp node_modules/ +.tmp-sprockets/ + diff --git a/bin/flowerbox b/bin/flowerbox index 459c9df..aa8ecf7 100755 --- a/bin/flowerbox +++ b/bin/flowerbox @@ -4,7 +4,9 @@ require 'flowerbox' require 'thor' class Flowerbox::CLI < Thor - desc "test DIR FILES...", "Run the specs found in spec dir, loading spec_helper.rb for configuration details" + include Thor::Actions + + desc "test", "Run the specs found in spec dir, loading spec_helper.rb for configuration details" method_options :pwd => :string, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false def test(dir = "spec/javascripts", *files) Dir.chdir(pwd) do @@ -33,6 +35,15 @@ class Flowerbox::CLI < Thor puts "Sprockets cache cleaned." end + desc "plant", "Start a new Flowerbox project" + def plant(type, dir = nil) + env = Flowerbox::TestEnvironment.for(type) + + self.class.source_root(Flowerbox.path.join(env.plant_source)) + + directory('.', dir || env.plant_target) + end + default_task :test no_tasks do diff --git a/lib/assets/javascripts/flowerbox/cucumber/reporter.js.coffee b/lib/assets/javascripts/flowerbox/cucumber/reporter.js.coffee index ded406e..6966442 100644 --- a/lib/assets/javascripts/flowerbox/cucumber/reporter.js.coffee +++ b/lib/assets/javascripts/flowerbox/cucumber/reporter.js.coffee @@ -49,6 +49,8 @@ class Flowerbox.Cucumber.Reporter result.status = Flowerbox.Result.PENDING else if stepResult.isUndefined() result.status = Flowerbox.Result.UNDEFINED + result.hasDataTable = @step.hasDataTable() + result.hasDocString = @step.hasDocString() else if stepResult.isFailed() result.status = Flowerbox.Result.FAILURE diff --git a/lib/flowerbox/test_environment/cucumber.rb b/lib/flowerbox/test_environment/cucumber.rb index 8c9df26..b614882 100644 --- a/lib/flowerbox/test_environment/cucumber.rb +++ b/lib/flowerbox/test_environment/cucumber.rb @@ -60,20 +60,34 @@ JS " (\d+) " end + messages = [] + + if result['hasDataTable'] + args << "table" + messages << "table is a Cucumber AST data table" + end + + if result['hasDocString'] + args << "string" + messages << "string is a doc string" + end + args_string = args.join(', ') + output = [] + if primarily_coffeescript? - <<-COFFEE -Flowerbox.#{result.step_type} /^#{matcher}$/, #{"(#{args_string}) " if !args_string.empty?}-> - @pending() # add your code here -COFFEE + output << %{Flowerbox.#{result.step_type} /^#{matcher}$/, #{"(#{args_string}) " if !args_string.empty?}->} + output += messages.collect { |msg| " # #{msg}" } + output << %{ @pending() # add your code here} else - <<-JS -Flowerbox.#{result.step_type}(/^#{matcher}$/, function(#{args_string}) { - this.pending(); // add your code here -}); -JS + output << "Flowerbox.#{result.step_type}(/^#{matcher}$/, function(#{args_string}) {" + output += messages.collect { |msg| " // #{msg}" } + output << %{ this.pending(); // add your code here} + output << "});" end + + output.collect { |line| "#{line}\n" }.join end def primarily_coffeescript? @@ -84,6 +98,14 @@ JS coffee_count > js_count end + + def plant_source + "skel/cucumber" + end + + def plant_target + "js-features" + end end end end diff --git a/skel/cucumber/features/my_first_feature.feature b/skel/cucumber/features/my_first_feature.feature new file mode 100644 index 0000000..1dd0d81 --- /dev/null +++ b/skel/cucumber/features/my_first_feature.feature @@ -0,0 +1,7 @@ +Feature: My First Feature + Scenario: Do Something + Given I have a flowerbox + When I plant a "cucumber" seed + Then I should get the following when I pick: + | cucumber | + diff --git a/skel/cucumber/spec_helper.rb b/skel/cucumber/spec_helper.rb new file mode 100644 index 0000000..ebf8442 --- /dev/null +++ b/skel/cucumber/spec_helper.rb @@ -0,0 +1,10 @@ +Flowerbox.configure do |f| + f.test_with :cucumber + f.run_with :firefox + + f.additional_files << "support/env.js.coffee" + f.spec_patterns << "features/**/*.feature" + + f.test_environment.prefer_step_language :coffeescript +end + diff --git a/skel/cucumber/step_definitions/given/i_have_a_flowerbox.js.coffee b/skel/cucumber/step_definitions/given/i_have_a_flowerbox.js.coffee new file mode 100644 index 0000000..2221119 --- /dev/null +++ b/skel/cucumber/step_definitions/given/i_have_a_flowerbox.js.coffee @@ -0,0 +1,8 @@ +Flowerbox.Given /^I have a flowerbox$/, -> + @flowerbox = + plantSeed: (type) -> + @types ||= [] + @types.push(type) + pick: -> + @types + diff --git a/skel/cucumber/step_definitions/then/i_should_get_the_following_when_i_pick.js.coffee b/skel/cucumber/step_definitions/then/i_should_get_the_following_when_i_pick.js.coffee new file mode 100644 index 0000000..b6d7f1b --- /dev/null +++ b/skel/cucumber/step_definitions/then/i_should_get_the_following_when_i_pick.js.coffee @@ -0,0 +1,5 @@ +Flowerbox.Then /^I should get the following when I pick:$/, (table) -> + # table is a Cucumber AST data table + data = (row[0] for row in table.raw()) + @expect(@flowerbox.pick()).toEqual(data) + diff --git a/skel/cucumber/step_definitions/when/i_plant_a_seed.js.coffee b/skel/cucumber/step_definitions/when/i_plant_a_seed.js.coffee new file mode 100644 index 0000000..9d98279 --- /dev/null +++ b/skel/cucumber/step_definitions/when/i_plant_a_seed.js.coffee @@ -0,0 +1,3 @@ +Flowerbox.When /^I plant a "([^"]+)" seed$/, (type) -> + @flowerbox.plantSeed(type) + diff --git a/skel/cucumber/support/env.js.coffee b/skel/cucumber/support/env.js.coffee new file mode 100644 index 0000000..624ee96 --- /dev/null +++ b/skel/cucumber/support/env.js.coffee @@ -0,0 +1 @@ +#= require_tree ../step_definitions