Support plural steps
This commit is contained in:
parent
760a165b2e
commit
42dbfc8a60
|
@ -7,3 +7,14 @@ Feature: Use step definitions generated by factories
|
|||
Then I should find the following for the last post:
|
||||
| title | a fun title |
|
||||
| body | here is the content |
|
||||
|
||||
Scenario: create several posts
|
||||
Given the following posts exist:
|
||||
| Title | Body |
|
||||
| one | first |
|
||||
| two | second |
|
||||
| three | third |
|
||||
Then I should find the following for the last post:
|
||||
| title | three |
|
||||
| body | third |
|
||||
And there should be 3 posts
|
||||
|
|
|
@ -6,3 +6,10 @@ Then /^I should find the following for the last post:$/ do |table|
|
|||
end
|
||||
end
|
||||
|
||||
Then /^there should be (\d+) posts$/ do |count|
|
||||
Post.count.should == count.to_i
|
||||
end
|
||||
|
||||
Before do
|
||||
Post.delete_all
|
||||
end
|
||||
|
|
|
@ -5,6 +5,13 @@ module FactoryGirlStepHelpers
|
|||
result.merge(key => value)
|
||||
end
|
||||
end
|
||||
|
||||
def convert_human_hash_to_attribute_hash(human_hash)
|
||||
human_hash.inject({}) do |attribute_hash, (human_key, value)|
|
||||
key = human_key.downcase.gsub(' ', '_').to_sym
|
||||
attribute_hash.merge(key => value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
World(FactoryGirlStepHelpers)
|
||||
|
@ -14,5 +21,12 @@ Factory.factories.values.each do |factory|
|
|||
attributes = convert_ast_table_to_attribute_hash(table)
|
||||
Factory.create(factory.factory_name, attributes)
|
||||
end
|
||||
|
||||
Given "the following #{factory.human_name}s exist:" do |table|
|
||||
table.hashes.each do |human_hash|
|
||||
attributes = convert_human_hash_to_attribute_hash(human_hash)
|
||||
Factory.create(factory.factory_name, attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue