judit-pickle 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +20 -0
  3. data/Gemfile.lock +98 -0
  4. data/History.txt +409 -0
  5. data/License.txt +20 -0
  6. data/README.rdoc +367 -0
  7. data/Rakefile +20 -0
  8. data/Rakefile.d/cucumber.rake +24 -0
  9. data/Rakefile.d/jeweler.rake +23 -0
  10. data/Rakefile.d/rcov.rake +18 -0
  11. data/Rakefile.d/rspec.rake +7 -0
  12. data/Rakefile.d/yard.rake +5 -0
  13. data/Todo.txt +3 -0
  14. data/VERSION +1 -0
  15. data/features/app/app.rb +122 -0
  16. data/features/app/blueprints.rb +11 -0
  17. data/features/app/factories.rb +23 -0
  18. data/features/app/views/notifier/email.erb +1 -0
  19. data/features/app/views/notifier/user_email.erb +6 -0
  20. data/features/email/email.feature +64 -0
  21. data/features/generator/generators.feature +59 -0
  22. data/features/path/models_page.feature +44 -0
  23. data/features/path/named_route_page.feature +10 -0
  24. data/features/pickle/create_from_active_record.feature +76 -0
  25. data/features/pickle/create_from_factory_girl.feature +63 -0
  26. data/features/pickle/create_from_machinist.feature +39 -0
  27. data/features/step_definitions/email_steps.rb +63 -0
  28. data/features/step_definitions/extra_email_steps.rb +7 -0
  29. data/features/step_definitions/fork_steps.rb +4 -0
  30. data/features/step_definitions/generator_steps.rb +46 -0
  31. data/features/step_definitions/path_steps.rb +14 -0
  32. data/features/step_definitions/pickle_steps.rb +100 -0
  33. data/features/step_definitions/raise_error_steps.rb +3 -0
  34. data/features/support/email.rb +21 -0
  35. data/features/support/env.rb +52 -0
  36. data/features/support/paths.rb +47 -0
  37. data/features/support/pickle.rb +26 -0
  38. data/features/support/pickle_app.rb +4 -0
  39. data/init.rb +0 -0
  40. data/lib/generators/pickle_generator.rb +69 -0
  41. data/lib/pickle/adapter.rb +137 -0
  42. data/lib/pickle/adapters/active_record.rb +57 -0
  43. data/lib/pickle/adapters/data_mapper.rb +42 -0
  44. data/lib/pickle/adapters/mongoid.rb +44 -0
  45. data/lib/pickle/config.rb +49 -0
  46. data/lib/pickle/email/parser.rb +18 -0
  47. data/lib/pickle/email/world.rb +13 -0
  48. data/lib/pickle/email.rb +77 -0
  49. data/lib/pickle/parser/matchers.rb +87 -0
  50. data/lib/pickle/parser.rb +65 -0
  51. data/lib/pickle/path/world.rb +5 -0
  52. data/lib/pickle/path.rb +45 -0
  53. data/lib/pickle/session/parser.rb +34 -0
  54. data/lib/pickle/session.rb +205 -0
  55. data/lib/pickle/version.rb +9 -0
  56. data/lib/pickle/world.rb +14 -0
  57. data/lib/pickle.rb +26 -0
  58. data/pickle.gemspec +134 -0
  59. data/rails_generators/pickle/pickle_generator.rb +33 -0
  60. data/rails_generators/pickle/templates/email.rb +21 -0
  61. data/rails_generators/pickle/templates/email_steps.rb +63 -0
  62. data/rails_generators/pickle/templates/paths.rb +47 -0
  63. data/rails_generators/pickle/templates/pickle.rb +28 -0
  64. data/rails_generators/pickle/templates/pickle_steps.rb +100 -0
  65. data/spec/pickle/adapter_spec.rb +186 -0
  66. data/spec/pickle/config_spec.rb +109 -0
  67. data/spec/pickle/email/parser_spec.rb +51 -0
  68. data/spec/pickle/email_spec.rb +166 -0
  69. data/spec/pickle/parser/matchers_spec.rb +70 -0
  70. data/spec/pickle/parser_spec.rb +161 -0
  71. data/spec/pickle/path_spec.rb +101 -0
  72. data/spec/pickle/session_spec.rb +434 -0
  73. data/spec/pickle_spec.rb +24 -0
  74. data/spec/spec_helper.rb +8 -0
  75. metadata +199 -0
@@ -0,0 +1,64 @@
1
+ Feature: I can test emails are sent
2
+ In order write features with emails as outcomes
3
+ As a feature writer
4
+ I want to easily see what emails have been delivered
5
+
6
+ Scenario: Deliver an email, and test it's properties
7
+ Given an email "Gday" with body: "Gday Mate" is delivered to fred@gmail.com
8
+ Then 1 email should be delivered
9
+ And the email should not be delivered to "frood@fmail.com"
10
+ And the email should have subject: "Gday", to: "fred@gmail.com"
11
+ And the email should contain "Mate"
12
+ And the email should not contain "Foo"
13
+
14
+ Scenario: Deliver some emails, restrict scope
15
+ Given an email "cool" with body: "body1" is delivered to fred@gmail.com
16
+ And an email "tasty" with body: "body2" is delivered to fred@gmail.com
17
+ And an email "cool" with body: "body3" is delivered to joe@gmail.com
18
+
19
+ Then 2 emails should be delivered to fred@gmail.com
20
+ And the 1st email should have subject: "cool"
21
+ And the 2nd email should have subject: "tasty"
22
+
23
+ And 2 emails should be delivered with subject: "cool"
24
+ And the 1st email should be delivered to fred@gmail.com
25
+ And the 2nd email should be delivered to joe@gmail.com
26
+
27
+ And 1 email should be delivered with subject: "cool", to: "fred@gmail.com"
28
+
29
+ Scenario: Deliver some emails, reset deliveries
30
+ Given an email "cool" with body: "body1" is delivered to fred@gmail.com
31
+ And all emails have been delivered
32
+ Then 0 emails should be delivered
33
+
34
+ Scenario: Deliver emails to user
35
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
36
+ And the user's email is delivered
37
+ Then 1 email should be delivered to the user
38
+ And the email should contain "Dear Fred"
39
+ And the email should link to the user's page
40
+
41
+ Scenario: Following the first link in an email
42
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
43
+ And an email "cool" with body: "some text <a href='http://example.com/users/1'>example page</a> more text" is delivered to fred@gmail.com
44
+ Then 1 email should be delivered to the user
45
+ And I click the first link in the email
46
+ Then I should be at the user's page
47
+
48
+ Scenario: Following a link in an email by url
49
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
50
+ And an email "cool" with body: "some text <a href='http://example.com/users/1'>example page</a> more text" is delivered to fred@gmail.com
51
+ Then 1 email should be delivered to the user
52
+ And I follow "example.com/" in the email
53
+ Then I should be at the user's page
54
+
55
+ Scenario: Following a link in an email by the text
56
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
57
+ And an email "cool" with body: "some text <a href='http://example.com/users/1'>example page</a> more text" is delivered to fred@gmail.com
58
+ Then 1 email should be delivered to the user
59
+ And I follow "example page" in the email
60
+ Then I should be at the user's page
61
+
62
+ Scenario: Save and open email
63
+ Given an email "Gday" with body: "Gday Mate" is delivered to fred@gmail.com
64
+ Then show me the email
@@ -0,0 +1,59 @@
1
+ @gen
2
+ Feature: allow pickle to generate steps
3
+ In order to get going with pickle
4
+ As a dev
5
+ I want to be able to generate steps
6
+
7
+ Scenario: script/generate pickle on fresh cuke install
8
+ Given cucumber has been freshly generated
9
+ When I run "script/generate pickle -f"
10
+ Then the file features/support/pickle.rb should exist
11
+ And the file features/support/pickle.rb should match /require 'pickle\/world'/
12
+ And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
13
+
14
+ Scenario: script/generate pickle path on fresh cuke install
15
+ Given cucumber has been freshly generated
16
+ When I run "script/generate pickle path -f"
17
+ Then the file features/support/pickle.rb should exist
18
+ And the file features/support/pickle.rb should match /require 'pickle\/world'/
19
+ And the file features/support/pickle.rb should match /require 'pickle\/path\/world'/
20
+ And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
21
+ And the file features/support/paths.rb should be identical to the local support/paths.rb
22
+
23
+ Scenario: script/generate pickle email on fresh cuke install
24
+ Given cucumber has been freshly generated
25
+ When I run "script/generate pickle email -f"
26
+ Then the file features/support/pickle.rb should exist
27
+ And the file features/support/pickle.rb should match /require 'pickle\/world'/
28
+ And the file features/support/pickle.rb should match /require 'pickle\/email\/world'/
29
+ And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
30
+ And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
31
+ And the file features/support/email.rb should be identical to the local support/email.rb
32
+
33
+ Scenario: script/generate pickle path email on fresh cuke install
34
+ Given cucumber has been freshly generated
35
+ When I run "script/generate pickle path email -f"
36
+ Then the file features/support/pickle.rb should exist
37
+ And the file features/support/pickle.rb should be identical to the local support/pickle.rb
38
+ And the file features/support/pickle.rb should match /require 'pickle\/world'/
39
+ And the file features/support/pickle.rb should match /require 'pickle\/path\/world'/
40
+ And the file features/support/pickle.rb should match /require 'pickle\/email\/world'/
41
+ And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
42
+ And the file features/support/paths.rb should be identical to the local support/paths.rb
43
+ And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
44
+ And the file features/support/email.rb should be identical to the local support/email.rb
45
+
46
+ Scenario: regenerating pickle
47
+ Given cucumber has been freshly generated
48
+ And pickle path email has been freshly generated
49
+ When I run "script/generate pickle path email -f"
50
+ Then the file features/support/pickle.rb should match /require 'pickle\/world'/
51
+ And the file features/support/pickle.rb should match /require 'pickle\/path\/world'/
52
+ And the file features/support/pickle.rb should match /require 'pickle\/email\/world'/
53
+ And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
54
+ And the file features/support/paths.rb should be identical to the local support/paths.rb
55
+ And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
56
+ But the file features/support/pickle.rb should not match /require 'pickle\/world'.*require 'pickle\/world'/
57
+ And the file features/support/pickle.rb should not match /require 'pickle\/path\/world'.*require 'pickle\/path\/world'/
58
+ And the file features/support/pickle.rb should not match /require 'pickle\/email\/world'.*require 'pickle\/email\/world'/
59
+ And the file features/support/email.rb should be identical to the local support/email.rb
@@ -0,0 +1,44 @@
1
+ Feature: I can visit a page for a model
2
+ In order to easily go to pages for models I've created
3
+ As a feature writer
4
+ I want to be able visit pages their model
5
+
6
+ Scenario: create a spoon, go its page
7
+ Given a spoon exists
8
+ When I go to the spoon's page
9
+ Then I should be at the spoon's page
10
+ And the spoon's page should match route /spoons/:id
11
+
12
+ Scenario: create a spoon, go to its edit page, check lots of different refs to it
13
+ Given a spoon: "fred" exists
14
+ When I go to spoon: "fred"'s edit page
15
+ Then I should be at the 1st spoon's edit page
16
+ And the 1st spoon's edit page should match route /spoons/:id/edit
17
+ And the spoon's edit page should match route /spoons/:id/edit
18
+ And the spoon: "fred"'s edit page should match route /spoons/:id/edit
19
+
20
+ Scenario: go to a fork's nested tines page
21
+ Given a fork exists
22
+ When I go to the fork's tines page
23
+ Then I should be at the fork's tines page
24
+ And the fork's tines page should match route /forks/:fork_id/tines
25
+
26
+ Scenario: go to a fork's new tine page
27
+ Given a fork exists
28
+ When I go to the fork's new tine page
29
+ Then I should be at the fork's new tine page
30
+ And the fork's new tine page should match route /forks/:fork_id/tines/new
31
+
32
+ Scenario: go to a tine in fork context page
33
+ Given a fork exists
34
+ And a tine exists with fork: the fork
35
+ When I go to the fork's tine's page
36
+ Then I should be at the fork's tine's page
37
+ And the fork's tine's page should match route /forks/:fork_id/tines/:id
38
+
39
+ Scenario: go to a tine's comments in fork context
40
+ Given a fork exists
41
+ And a tine exists with fork: the fork
42
+ When I go to the fork's tine's comments page
43
+ Then I should be at the fork's tine's comments page
44
+ And the fork's tine's comments page should match route /forks/:fork_id/tines/:tine_id/comments
@@ -0,0 +1,10 @@
1
+ Feature: I can visit a page by named route
2
+ In order to nav in my features
3
+ As a feature writer
4
+ I want to be able visit named routes
5
+
6
+ Scenario: visit the new spoons page
7
+ When I go to the new spoon page
8
+ Then I should be at the new spoon page
9
+ And the new spoon page should match route /spoons/new
10
+
@@ -0,0 +1,76 @@
1
+ Feature: I can easily create models from my blueprints
2
+
3
+ As a plain old AR user
4
+ I want to be able to create models with fields
5
+ So that I can create models quickly and easily in my features
6
+
7
+
8
+ Scenario: I create a user, and see if it looks right
9
+ Given a user exists with name: "Fred", has_stale_password: true
10
+ Then the user should not have a status
11
+ And the user should have a stale password
12
+ And the user's name should be "Fred"
13
+
14
+ Scenario: I create a user, and see if it looks right
15
+ Given a user exists with name: "Fred", status: "crayzee"
16
+ Then a user should exist with name: "Fred"
17
+ And a user should exist with status: "crayzee"
18
+ But a user should not exist with name: "Wilma"
19
+
20
+ Scenario: I create a user via a mapping
21
+ Given I exist with status: "pwned", name: "fred"
22
+ Then I should have a status
23
+ And the user: "me" should have a status
24
+
25
+ Scenario: I create positive and negative users
26
+ Given a user exists with name: "Fred", attitude_score: +5.42
27
+ And another user exists with name: "Ethel", attitude_score: -10
28
+ And another user exists with name: "Buddha", attitude_score: 2_000_000
29
+ Then 3 users should exist
30
+ And the 1st user should be a positive person
31
+ And the 2nd user should not be a positive person
32
+ And the 1st user's attitude_score should be 5.42
33
+ And the 2nd user's attitude_score should be -10
34
+ And the 3rd user's attitude_score should be 2_000_000
35
+ And the 3rd user's attitude_score should be 2000000
36
+
37
+ Scenario: I create nil values
38
+ Given a user exists with name: "Fred", attitude_score: nil
39
+ Then 1 users should exist with attitude_score: nil
40
+ And that user should be the first user
41
+ And that user should have no attitude
42
+ And that user's attitude_score should be nil
43
+
44
+ Scenario: create and find using tables
45
+ Given the following users exist:
46
+ | name | status |
47
+ | Jim | married |
48
+ | Ethel | in a relationship with x |
49
+ Then the following users should exist:
50
+ | name |
51
+ | Jim |
52
+ | Ethel |
53
+ And the following users should exist:
54
+ | status |
55
+ | married |
56
+ | in a relationship with x |
57
+ And the 1st user should be the 3rd user
58
+ And the 2nd user should be the last user
59
+
60
+ Scenario: create and find using tables with referencable names
61
+ Given the following users exist:
62
+ | user | name | status |
63
+ | Jack | Jack | alone |
64
+ | Pete | Pete | dead |
65
+ Then the following users should exist:
66
+ | name |
67
+ | Jack |
68
+ | Pete |
69
+ And the following users should exist:
70
+ | user | status |
71
+ | lonely | alone |
72
+ | rotting | dead |
73
+ And the 1st user should be the user: "Jack"
74
+ And the 2nd user should be the user: "Pete"
75
+ And the user: "lonely" should be the user: "Jack"
76
+ And the user: "rotting" should be the user: "Pete"
@@ -0,0 +1,63 @@
1
+ Feature: I can easily create models from my factories
2
+
3
+ As a pickle user
4
+ I want to be able to leverage my factories
5
+ So that I can create models quickly and easily in my features
6
+
7
+ Scenario: I create a fork, and see if it looks right
8
+ Given a fork exists
9
+ Then the fork should not be completely rusty
10
+
11
+ Scenario: I create a fork, and see if it looks right
12
+ Given a fork exists with name: "Forky"
13
+ Then a fork should exist with name: "Forky"
14
+ And the fork should not be completely rusty
15
+
16
+ Scenario: I create some forks, and some tines
17
+ Given a fork: "one" exists
18
+ And a tine exists with fork: fork "one"
19
+ And another tine exists with fork: fork "one"
20
+
21
+ And a fancy fork exists
22
+ And a tine exists with fork: the fancy fork
23
+
24
+ Then the first tine should be tine of the fork: "one"
25
+ And the 2nd tine should be tine of fork: "one"
26
+ And the last tine should be tine of the fancy fork
27
+
28
+ Then the first tine should be in fork "one"'s tines
29
+ And the 2nd tine should be in fork: "one"'s tines
30
+ And the last tine should be in the fancy fork's tines
31
+ And the fancy fork should be the last tine's fork
32
+
33
+ But the first tine should not be in the fancy fork's tines
34
+ And the last tine should not be in fork "one"'s tines
35
+ And the fancy fork should not be the first tine's fork
36
+
37
+ Scenario: I create a fork with a tine, and find the tine by the fork
38
+ Given a fork exists
39
+ And a tine exists with fork: the fork
40
+
41
+ Then a tine should exist with fork: the fork
42
+
43
+ Scenario: create a tine with fork refs in a table
44
+ Given 2 forks exist
45
+ And the following tines exist:
46
+ | fork |
47
+ | the 1st fork |
48
+ | the 2nd fork |
49
+ | the 2nd fork |
50
+ Then the 1st tine should be in the 1st fork's tines
51
+ And the 2nd tine should be in the 2nd fork's tines
52
+ And the 3rd tine should be in the 2nd fork's tines
53
+ And the 1st fork should have 1 tines
54
+ And the 2nd fork should have 2 tines
55
+
56
+ Scenario: I create fork via a mapping
57
+ Given killah fork exists
58
+ Then the fork should be fancy
59
+ And the fancy fork: "of cornwood" should be fancy
60
+
61
+ Scenario: create a tine with a missing fork
62
+ Then the following should raise Pickle::Session::ModelNotKnownError: "Given a tine exists with fork: the fork"
63
+
@@ -0,0 +1,39 @@
1
+ Feature: I can easily create models from my blueprints
2
+
3
+ As a machinist user
4
+ I want to be able to leverage my blueprints
5
+ So that I can create models quickly and easily in my features
6
+
7
+ Scenario: I create a spoon, and see if it looks right
8
+ Given a spoon exists
9
+ Then the spoon should be round
10
+ And the spoon's round should be true
11
+
12
+ Scenario: I create a non round spoon, and see if it looks right
13
+ Given a spoon exists with round: false
14
+ Then the spoon should not be round
15
+
16
+ Scenario: I create a named spoon, and see if it has the name
17
+ Given a spoon exists with name: "Pete", round: false
18
+ Then a spoon should exist with name: "Pete"
19
+ And the spoon should not be round
20
+
21
+ Scenario: I create 7 spoons of various roundness
22
+ Given 2 spoons exist with round: false
23
+ And 2 spoons exist with round: true
24
+ And a spoon exists with round: false
25
+
26
+ Then the 1st spoon should not be round
27
+ And the 2nd spoon should not be round
28
+ And the 3rd spoon should be round
29
+ And the 4th spoon should be round
30
+ And the 5th spoon should not be round
31
+
32
+ And 3 spoons should exist with round: false
33
+ And the 1st spoon should not be round
34
+ And the 2nd spoon should not be round
35
+ And the last spoon should not be round
36
+
37
+ And 2 spoons should exist with round: true
38
+ And the first spoon should be round
39
+ And the last spoon should be round
@@ -0,0 +1,63 @@
1
+ # this file generated by script/generate pickle email
2
+ #
3
+ # add email mappings in features/support/email.rb
4
+
5
+ ActionMailer::Base.delivery_method = :test
6
+ ActionMailer::Base.perform_deliveries = true
7
+
8
+ Before do
9
+ ActionMailer::Base.deliveries.clear
10
+ end
11
+
12
+ # Clear the deliveries array, useful if your background sends email that you want to ignore
13
+ Given(/^all emails? (?:have|has) been delivered$/) do
14
+ ActionMailer::Base.deliveries.clear
15
+ end
16
+
17
+ Given(/^(\d)+ emails? should be delivered$/) do |count|
18
+ emails.size.should == count.to_i
19
+ end
20
+
21
+ When(/^(?:I|they) follow "([^"]*?)" in #{capture_email}$/) do |link, email_ref|
22
+ visit_in_email(email(email_ref), link)
23
+ end
24
+
25
+ When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
26
+ click_first_link_in_email(email(email_ref))
27
+ end
28
+
29
+ Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
30
+ emails("to: \"#{email_for(to)}\"").size.should == count.to_i
31
+ end
32
+
33
+ Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
34
+ emails(fields).size.should == count.to_i
35
+ end
36
+
37
+ Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
38
+ email(email_ref, "to: \"#{email_for(to)}\"").should_not be_nil
39
+ end
40
+
41
+ Then(/^#{capture_email} should not be delivered to (.+)$/) do |email_ref, to|
42
+ email(email_ref, "to: \"#{email_for(to)}\"").should be_nil
43
+ end
44
+
45
+ Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
46
+ email(email_ref, fields).should_not be_nil
47
+ end
48
+
49
+ Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
50
+ email(email_ref).body.should =~ /#{text}/
51
+ end
52
+
53
+ Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
54
+ email(email_ref).body.should_not =~ /#{text}/
55
+ end
56
+
57
+ Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
58
+ email(email_ref).body.should =~ /#{path_to(page)}/
59
+ end
60
+
61
+ Then(/^show me the emails?$/) do
62
+ save_and_open_emails
63
+ end
@@ -0,0 +1,7 @@
1
+ Given(/^an email "(.*?)" with body: "(.*?)" is delivered to (.+?)$/) do |subject, body, to|
2
+ Notifier.deliver_email(to, subject, body)
3
+ end
4
+
5
+ Given(/^#{capture_model}'s email is delivered$/) do |model|
6
+ Notifier.deliver_user_email(model(model))
7
+ end
@@ -0,0 +1,4 @@
1
+ # example of making your own matcher with the pickle backend
2
+ Then(/^#{capture_model} should be tine of #{capture_model}$/) do |tine, fork|
3
+ model(fork).tines.should include(model(tine))
4
+ end
@@ -0,0 +1,46 @@
1
+ Before('@gen') do
2
+ `mv #{Rails.root}/features/ #{Rails.root}/features.orig/ > /dev/null 2>&1`
3
+ end
4
+
5
+ After('@gen') do
6
+ `rm -rf #{Rails.root}/features`
7
+ `mv #{Rails.root}/features.orig/ #{Rails.root}/features/ > /dev/null 2>&1`
8
+ end
9
+
10
+ Given(/^cucumber has been freshly generated$/) do
11
+ `cd #{Rails.root}; script/generate cucumber -f --webrat`
12
+ end
13
+
14
+ Given(/^pickle path email has been freshly generated$/) do
15
+ `cd #{Rails.root}; script/generate -f pickle paths email`
16
+ end
17
+
18
+ Given(/^env\.rb already requires (.+)$/) do |file|
19
+ File.open("#{Rails.root}/features/support/env.rb", "a") do |env|
20
+ env << "require '#{file}'\n"
21
+ end
22
+ end
23
+
24
+ When(/^I run "(.*)"$/) do |command|
25
+ @output = `cd #{Rails.root}; #{command}`
26
+ end
27
+
28
+ Then(/^I should see "(.*)"$/) do |text|
29
+ @output.should include(text)
30
+ end
31
+
32
+ Then(/^the file (.+?) should exist$/) do |file|
33
+ File.exist?("#{Rails.root}/#{file}").should == true
34
+ end
35
+
36
+ Then(/^the file (.+?) should match \/(.*?)\/$/) do |file, regexp|
37
+ File.read("#{Rails.root}/#{file}").should match(/#{regexp}/m)
38
+ end
39
+
40
+ Then(/^the file (.+?) should not match \/(.*?)\/$/) do |file, regexp|
41
+ File.read("#{Rails.root}/#{file}").should_not match(/#{regexp}/m)
42
+ end
43
+
44
+ Then /^the file ([^ ]+) should be identical to the local (.+)$/ do |generated_file, source_file|
45
+ File.read("#{Rails.root}/#{generated_file}").should == File.read("#{File.dirname(__FILE__)}/../#{source_file}")
46
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
+
3
+ Then(/^(.+?) should match route \/(.+?)$/) do |page, route|
4
+ regexp = route.gsub(/:(\w*?)id/,'\d+')
5
+ path_to(page).should =~ /#{regexp}/
6
+ end
7
+
8
+ When(/^I go to (.+)$/) do |page|
9
+ visit path_to(page)
10
+ end
11
+
12
+ Then(/^I should be at (.+)$/) do |page|
13
+ request.path.should =~ /#{path_to(page)}/
14
+ end
@@ -0,0 +1,100 @@
1
+ # this file generated by script/generate pickle
2
+
3
+ # create a model
4
+ Given(/^#{capture_model} exists?(?: with #{capture_fields})?$/) do |name, fields|
5
+ create_model(name, fields)
6
+ end
7
+
8
+ # create n models
9
+ Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
10
+ count.to_i.times { create_model(plural_factory.singularize, fields) }
11
+ end
12
+
13
+ # create models from a table
14
+ Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
15
+ create_models_from_table(plural_factory, table)
16
+ end
17
+
18
+ # find a model
19
+ Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
20
+ find_model!(name, fields)
21
+ end
22
+
23
+ # not find a model
24
+ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
25
+ find_model(name, fields).should be_nil
26
+ end
27
+
28
+ # find models with a table
29
+ Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
30
+ find_models_from_table(plural_factory, table).should_not be_any(&:nil?)
31
+ end
32
+
33
+ # find exactly n models
34
+ Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
35
+ find_models(plural_factory.singularize, fields).size.should == count.to_i
36
+ end
37
+
38
+ # assert equality of models
39
+ Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
40
+ model!(a).should == model!(b)
41
+ end
42
+
43
+ # assert model is in another model's has_many assoc
44
+ Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
45
+ model!(owner).send(association).should include(model!(target))
46
+ end
47
+
48
+ # assert model is not in another model's has_many assoc
49
+ Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
50
+ model!(owner).send(association).should_not include(model!(target))
51
+ end
52
+
53
+ # assert model is another model's has_one/belongs_to assoc
54
+ Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
55
+ model!(owner).send(association).should == model!(target)
56
+ end
57
+
58
+ # assert model is not another model's has_one/belongs_to assoc
59
+ Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
60
+ model!(owner).send(association).should_not == model!(target)
61
+ end
62
+
63
+ # assert model.predicate?
64
+ Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
65
+ if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
66
+ model!(name).should send("have_#{predicate.gsub(' ', '_')}")
67
+ else
68
+ model!(name).should send("be_#{predicate.gsub(' ', '_')}")
69
+ end
70
+ end
71
+
72
+ # assert not model.predicate?
73
+ Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
74
+ if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
75
+ model!(name).should_not send("have_#{predicate.gsub(' ', '_')}")
76
+ else
77
+ model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
78
+ end
79
+ end
80
+
81
+ # model.attribute.should eql(value)
82
+ # model.attribute.should_not eql(value)
83
+ Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
84
+ actual_value = model(name).send(attribute)
85
+ expectation = expectation.gsub(' ', '_')
86
+
87
+ case expected
88
+ when 'nil', 'true', 'false'
89
+ actual_value.send(expectation, send("be_#{expected}"))
90
+ when /^[+-]?[0-9_]+(\.\d+)?$/
91
+ actual_value.send(expectation, eql(expected.to_f))
92
+ else
93
+ actual_value.to_s.send(expectation, eql(eval(expected)))
94
+ end
95
+ end
96
+
97
+ # assert size of association
98
+ Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
99
+ model!(name).send(association).size.should == size.to_i
100
+ end
@@ -0,0 +1,3 @@
1
+ Then /^the following should raise Pickle::Session::ModelNotKnownError: "([^"]*)"$/ do |step|
2
+ lambda { steps step }.should raise_error(Pickle::Session::ModelNotKnownError)
3
+ end
@@ -0,0 +1,21 @@
1
+ module EmailHelpers
2
+ # Maps a name to an email address. Used by email_steps
3
+
4
+ def email_for(to)
5
+ case to
6
+
7
+ # add your own name => email address mappings here
8
+
9
+ when /^#{capture_model}$/
10
+ model($1).email
11
+
12
+ when /^"(.*)"$/
13
+ $1
14
+
15
+ else
16
+ to
17
+ end
18
+ end
19
+ end
20
+
21
+ World(EmailHelpers)