make it possible to bootstrap a cucumber config, handle tables and strings in cucumber tasks
This commit is contained in:
parent
4b463428ea
commit
b729812f76
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,3 +17,5 @@ test/version_tmp
|
|||||||
tmp
|
tmp
|
||||||
.tmp
|
.tmp
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.tmp-sprockets/
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ require 'flowerbox'
|
|||||||
require 'thor'
|
require 'thor'
|
||||||
|
|
||||||
class Flowerbox::CLI < 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
|
method_options :pwd => :string, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false
|
||||||
def test(dir = "spec/javascripts", *files)
|
def test(dir = "spec/javascripts", *files)
|
||||||
Dir.chdir(pwd) do
|
Dir.chdir(pwd) do
|
||||||
@ -33,6 +35,15 @@ class Flowerbox::CLI < Thor
|
|||||||
puts "Sprockets cache cleaned."
|
puts "Sprockets cache cleaned."
|
||||||
end
|
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
|
default_task :test
|
||||||
|
|
||||||
no_tasks do
|
no_tasks do
|
||||||
|
@ -49,6 +49,8 @@ class Flowerbox.Cucumber.Reporter
|
|||||||
result.status = Flowerbox.Result.PENDING
|
result.status = Flowerbox.Result.PENDING
|
||||||
else if stepResult.isUndefined()
|
else if stepResult.isUndefined()
|
||||||
result.status = Flowerbox.Result.UNDEFINED
|
result.status = Flowerbox.Result.UNDEFINED
|
||||||
|
result.hasDataTable = @step.hasDataTable()
|
||||||
|
result.hasDocString = @step.hasDocString()
|
||||||
else if stepResult.isFailed()
|
else if stepResult.isFailed()
|
||||||
result.status = Flowerbox.Result.FAILURE
|
result.status = Flowerbox.Result.FAILURE
|
||||||
|
|
||||||
|
@ -60,20 +60,34 @@ JS
|
|||||||
" (\d+) "
|
" (\d+) "
|
||||||
end
|
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(', ')
|
args_string = args.join(', ')
|
||||||
|
|
||||||
|
output = []
|
||||||
|
|
||||||
if primarily_coffeescript?
|
if primarily_coffeescript?
|
||||||
<<-COFFEE
|
output << %{Flowerbox.#{result.step_type} /^#{matcher}$/, #{"(#{args_string}) " if !args_string.empty?}->}
|
||||||
Flowerbox.#{result.step_type} /^#{matcher}$/, #{"(#{args_string}) " if !args_string.empty?}->
|
output += messages.collect { |msg| " # #{msg}" }
|
||||||
@pending() # add your code here
|
output << %{ @pending() # add your code here}
|
||||||
COFFEE
|
|
||||||
else
|
else
|
||||||
<<-JS
|
output << "Flowerbox.#{result.step_type}(/^#{matcher}$/, function(#{args_string}) {"
|
||||||
Flowerbox.#{result.step_type}(/^#{matcher}$/, function(#{args_string}) {
|
output += messages.collect { |msg| " // #{msg}" }
|
||||||
this.pending(); // add your code here
|
output << %{ this.pending(); // add your code here}
|
||||||
});
|
output << "});"
|
||||||
JS
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
output.collect { |line| "#{line}\n" }.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def primarily_coffeescript?
|
def primarily_coffeescript?
|
||||||
@ -84,6 +98,14 @@ JS
|
|||||||
|
|
||||||
coffee_count > js_count
|
coffee_count > js_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def plant_source
|
||||||
|
"skel/cucumber"
|
||||||
|
end
|
||||||
|
|
||||||
|
def plant_target
|
||||||
|
"js-features"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
7
skel/cucumber/features/my_first_feature.feature
Normal file
7
skel/cucumber/features/my_first_feature.feature
Normal 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 |
|
||||||
|
|
10
skel/cucumber/spec_helper.rb
Normal file
10
skel/cucumber/spec_helper.rb
Normal 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
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
Flowerbox.Given /^I have a flowerbox$/, ->
|
||||||
|
@flowerbox =
|
||||||
|
plantSeed: (type) ->
|
||||||
|
@types ||= []
|
||||||
|
@types.push(type)
|
||||||
|
pick: ->
|
||||||
|
@types
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -0,0 +1,3 @@
|
|||||||
|
Flowerbox.When /^I plant a "([^"]+)" seed$/, (type) ->
|
||||||
|
@flowerbox.plantSeed(type)
|
||||||
|
|
1
skel/cucumber/support/env.js.coffee
Normal file
1
skel/cucumber/support/env.js.coffee
Normal file
@ -0,0 +1 @@
|
|||||||
|
#= require_tree ../step_definitions
|
Loading…
Reference in New Issue
Block a user