make it possible to bootstrap a cucumber config, handle tables and strings in cucumber tasks

This commit is contained in:
John Bintz 2012-03-17 17:54:23 -04:00
parent 4b463428ea
commit b729812f76
10 changed files with 81 additions and 10 deletions

2
.gitignore vendored
View File

@ -17,3 +17,5 @@ test/version_tmp
tmp
.tmp
node_modules/
.tmp-sprockets/

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 |

View File

@ -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

View File

@ -0,0 +1,8 @@
Flowerbox.Given /^I have a flowerbox$/, ->
@flowerbox =
plantSeed: (type) ->
@types ||= []
@types.push(type)
pick: ->
@types

View File

@ -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)

View File

@ -0,0 +1,3 @@
Flowerbox.When /^I plant a "([^"]+)" seed$/, (type) ->
@flowerbox.plantSeed(type)

View File

@ -0,0 +1 @@
#= require_tree ../step_definitions