Permalink
Browse files

Better advice for creating a task and a general tidy up

  • Loading branch information...
1 parent 4e87652 commit 170fcd3596930b994850b62e67d3c7e1b23e48e0 @antonymarcano antonymarcano committed Sep 17, 2011
@@ -5,32 +5,31 @@ Feature: Prepare the actor for the role
Scenario: Initialization
Given you are a Step Free Cuker
- And you were able to create a file, at 'features/roles/role_with_prep.rb' containing
- """
- module RoleWithPrep
- def role_preparation
- do_something_important
- end
+ And you have created a file, at 'features/roles/role_with_prep.rb' containing
+ """
+ module RoleWithPrep
+ def role_preparation
+ do_something_important
+ end
- def do_something_important
- @something = 'something important was done'
- end
+ def do_something_important
+ @something = 'something important was done'
+ end
- def see_what_was_done
- @something
+ def see_what_was_done
+ @something
+ end
end
- end
- """
- And you were able to create a task, called 'see that' containing
- """
- in_order_to 'see that' do
- see_what_was_done
- end
- """
- When you attempt to run a scenario, containing
- """
- Given I am a Role With Prep
- Then I should see that 'something important was done'
- """
+ """
+ And you have created a task, called 'see that' containing
+ """
+ in_order_to 'see that' do
+ see_what_was_done
+ end
+ """
+ When you run a scenario, containing
+ """
+ Given I am a Role With Prep
+ Then I should see that 'something important was done'
+ """
Then you should see it has 'passed'
-
@@ -6,10 +6,9 @@ Feature: Define a Task
Background:
Given you are a Step Free Cuker
- And you have created a role, named 'NewCustomer'
+ And you have created a role, named 'NewCustomer'
Scenario: We'll tell you what you need to do to describe the task
- Given you did not create a task: called 'do something'
When you run a scenario: containing
"""
Given I am a New Customer
@@ -21,54 +20,55 @@ Feature: Define a Task
I can't find a task called 'do something'. Have you created it?
e.g.
in_order_to 'do something' do
- # the actions
+ raise "TODO: You need to explain how to 'do something'"
end
"""
Scenario: Once you've created a task, you can use it in a Given step
- Given you were able to create a task, called 'have something'
- When you run a scenario, containing
- """
- Given I am a New Customer
- Given I have something
- """
+ Given you have created a task, called 'done something'
+ When you run a scenario, containing
+ """
+ Given I am a New Customer
+ And I have done something
+ """
Then you should see it has 'passed'
Scenario: Tasks can be used in a When step too
- Given you were able to create a task, called 'do something'
- When you run a scenario, containing
- """
- Given I am a New Customer
- When I do something
- """
+ Given you have created a task, called 'do something'
+ When you run a scenario, containing
+ """
+ Given I am a New Customer
+ When I do something
+ """
Then you should see it has 'passed'
Scenario: You can reuse a step between a Given and a When step
- Given you were able to create a task, called 'do something'
- When you run a scenario, containing
- """
- Given I am a New Customer
- And you were able to do something
- When I do something
- """
+ Given you have created a task, called 'do something'
+ When you run a scenario, containing
+ """
+ Given I am a New Customer
+ And you were able to do something
+ When I do something
+ """
Then you should see it has 'passed'
Scenario: Tasks can contain numbers
- Given you were able to create a task: called 'do something for 123Company'
- When you run a scenario: containing
- """
- Given I am a New Customer
- When I do something for 123Company
- """
+ Given you have created a task: called 'do something for 123Company'
+ When you run a scenario: containing
+ """
+ Given I am a New Customer
+ When I do something for 123Company
+ """
Then you should see it has 'passed'
Scenario Outline: There are all sorts of ways you can say things
- Given you were able to create a task: called 'do something'
- When you run a scenario: containing
- """
- Given I am a New Customer
- <step using the task>
- """
+ Given you have created a task, called 'do something'
+ And you have created a task, called 'done something'
+ When you run a scenario: containing
+ """
+ Given I am a New Customer
+ <step using the task>
+ """
Then you should see it has 'passed'
Examples:
@@ -89,4 +89,3 @@ Feature: Define a Task
| And I should do something |
| Then you should do something |
| And you should do something |
-
@@ -5,22 +5,22 @@ Feature: Remember information between steps
Background:
Given you are a Step Free Cuker
- And you have created a role, named 'NewCustomer'
+ And you have created a role, named 'NewCustomer'
Scenario: You can reuse information
- Given you were able to create a task, called 'do something' containing
+ Given you have created a task, called 'do something' containing
"""
in_order_to 'do something', remembering: :value do
take_note_of :some_key, the( :value )
end
"""
- And you were able to create a task, called 'find that the thing remembered was' containing
+ And you have created a task, called 'find that the thing remembered was' containing
"""
in_order_to 'find that the thing remembered was' do
recall :some_key
end
"""
- When you attempt to run a scenario, containing
+ When you run a scenario, containing
"""
Given I am a New Customer
When I attempt to do something, remembering 'a value'
@@ -30,13 +30,13 @@ Feature: Remember information between steps
Scenario: You'll get feedback if you ask for something that wasn't noted
Given you did not previously take note of something
- And you were able to create a task, called 'find that the thing remembered was' containing
+ And you have created a task, called 'find that the thing remembered was' containing
"""
in_order_to 'find that the thing remembered was' do
recall :some_key
end
"""
- When I attempt to run a scenario, containing
+ When I run a scenario, containing
"""
Given I am a New Customer
Then I should find that the thing remembered was 'a value'
@@ -46,4 +46,3 @@ Feature: Remember information between steps
"""
You tried to recall ':some_key' but no previous step appears to have taken note of that information
"""
-
@@ -5,32 +5,32 @@ Feature: Expressing expectations
Background:
Given you are a Step Free Cuker
- And you were able to create a file, at 'features/roles/role_with_answers.rb' containing
- """
- module RoleWithAnswers
- def see_the_answer
- get_the_answer_from_the_application
- end
+ And you have created a file, at 'features/roles/role_with_answers.rb' containing
+ """
+ module RoleWithAnswers
+ def see_the_answer
+ get_the_answer_from_the_application
+ end
- def get_the_answer_from_the_application
- # Pretending to get the answer from the application
- return 'correct answer'
+ def get_the_answer_from_the_application
+ # Pretending to get the answer from the application
+ return 'correct answer'
+ end
+ end
+ """
+ And you have created a task, called 'see the answer is' containing
+ """
+ in_order_to 'see the answer is' do
+ see_the_answer
end
- end
- """
- And you were able to create a task, called 'see the answer is' containing
- """
- in_order_to 'see the answer is' do
- see_the_answer
- end
- """
+ """
Scenario Outline: Simple Expectation
- When you attempt to run a scenario, containing
- """
- Given I am a Role With Answers
- Then I should see the answer is <answer>
- """
+ When you run a scenario, containing
+ """
+ Given I am a Role With Answers
+ Then I should see the answer is <answer>
+ """
Then you should see it has 'passed'
Examples:
@@ -1,3 +1,3 @@
-in_order_to 'have created a role', named: :role_name do
+in_order_to 'created a role', named: :role_name do
write_file 'features/lib/roles/my_role.rb', "module #{the :role_name}\nend"
end
@@ -1,12 +1,14 @@
-in_order_to 'create a task', called: :name_of_task, containing: :code do
- file_name = the( :name_of_task ).gsub(" ", "_")
-
- default_content =
- "in_order_to '#{the :name_of_task}' do
- #nothing
- end"
- content = the :code
- content = default_content if content.nil?
+['create a task', 'created a task'].each do | create_a_new_task |
+ in_order_to create_a_new_task, called: :name_of_task, containing: :code do
+ file_name = the( :name_of_task ).gsub(" ", "_")
+
+ default_content =
+ "in_order_to '#{the :name_of_task}' do
+ #nothing
+ end"
+ content = the :code
+ content = default_content if content.nil?
- write_file "features/lib/tasks/#{file_name}.rb", content
+ write_file "features/lib/tasks/#{file_name}.rb", content
+ end
end
@@ -1,4 +1,4 @@
-in_order_to "RunAScenario", containing: :steps do
+in_order_to 'run a scenario', containing: :steps do
write_file 'features/a.feature', "Feature: A Feature
Scenario: A Scenario
@@ -11,7 +11,7 @@ def in_order_to(do_something, *with_attributes, &actions)
@actor = CukeSalad::Actor.new(role)
end
-When /^(?:I (?!am)|you (?!are))(?:attempt to |was able to |were able to |did )?((?!should)[A-Z a-z\d_-]*)(?:[:|,] (.*))?:?$/ do | this_task, details, *and_more |
+When /^(?:I (?!am)|you (?!are))(?:attempt to |was able to |were able to |did |have )?((?!should)[A-Z a-z\d_-]*)(?:[:|,] (.*))?:?$/ do | this_task, details, *and_more |
info = understand_the details unless details.nil?
info[info.keys.last] = and_more[0] unless and_more.empty?
@actor.perform this_task, info unless info.nil?
@@ -19,7 +19,7 @@ def how_do_i_perform something
begin
find_directives_for name
rescue NameError
- raise "I can't find a task called '#{ something }'. Have you created it?\ne.g.\n in_order_to '#{ something }' do\n # the actions\n end\n\n"
+ raise "I can't find a task called '#{ something }'. Have you created it?\ne.g.\n in_order_to '#{ something }' do\n raise \"TODO: You need to explain how to '#{ something }'\"\n end\n\n"
end
end

0 comments on commit 170fcd3

Please sign in to comment.