email_spec 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. data/History.txt +17 -1
  2. data/README.md +340 -0
  3. data/Rakefile +3 -50
  4. data/lib/email_spec.rb +3 -2
  5. data/lib/email_spec/email_viewer.rb +10 -6
  6. data/lib/email_spec/errors.rb +7 -0
  7. data/lib/email_spec/helpers.rb +5 -3
  8. data/lib/email_spec/matchers.rb +166 -66
  9. data/rails_generators/email_spec/templates/email_steps.rb +1 -1
  10. metadata +290 -236
  11. data/README.rdoc +0 -148
  12. data/examples/rails3_root/Gemfile +0 -17
  13. data/examples/rails3_root/Gemfile.lock +0 -135
  14. data/examples/rails3_root/README +0 -5
  15. data/examples/rails3_root/Rakefile +0 -11
  16. data/examples/rails3_root/app/controllers/application_controller.rb +0 -3
  17. data/examples/rails3_root/app/controllers/welcome_controller.rb +0 -16
  18. data/examples/rails3_root/app/helpers/application_helper.rb +0 -2
  19. data/examples/rails3_root/app/mailers/user_mailer.rb +0 -39
  20. data/examples/rails3_root/app/models/user.rb +0 -2
  21. data/examples/rails3_root/app/views/user_mailer/attachments.html.erb +0 -6
  22. data/examples/rails3_root/app/views/user_mailer/newsletter.html.erb +0 -8
  23. data/examples/rails3_root/app/views/user_mailer/signup.html.erb +0 -4
  24. data/examples/rails3_root/app/views/user_mailer/signup.text.erb +0 -4
  25. data/examples/rails3_root/app/views/welcome/attachments.html.erb +0 -0
  26. data/examples/rails3_root/app/views/welcome/confirm.html.erb +0 -1
  27. data/examples/rails3_root/app/views/welcome/index.html.erb +0 -8
  28. data/examples/rails3_root/app/views/welcome/newsletter.html.erb +0 -0
  29. data/examples/rails3_root/app/views/welcome/signup.html.erb +0 -1
  30. data/examples/rails3_root/attachments/document.pdf +0 -0
  31. data/examples/rails3_root/attachments/image.png +0 -0
  32. data/examples/rails3_root/config.ru +0 -4
  33. data/examples/rails3_root/config/application.rb +0 -43
  34. data/examples/rails3_root/config/boot.rb +0 -14
  35. data/examples/rails3_root/config/cucumber.yml +0 -8
  36. data/examples/rails3_root/config/database.yml +0 -25
  37. data/examples/rails3_root/config/environment.rb +0 -6
  38. data/examples/rails3_root/config/environments/development.rb +0 -20
  39. data/examples/rails3_root/config/environments/production.rb +0 -42
  40. data/examples/rails3_root/config/environments/test.rb +0 -30
  41. data/examples/rails3_root/config/initializers/backtrace_silencers.rb +0 -7
  42. data/examples/rails3_root/config/initializers/cookie_verification_secret.rb +0 -7
  43. data/examples/rails3_root/config/initializers/delayed_job.rb +0 -1
  44. data/examples/rails3_root/config/initializers/inflections.rb +0 -10
  45. data/examples/rails3_root/config/initializers/mime_types.rb +0 -5
  46. data/examples/rails3_root/config/initializers/notifier_job.rb +0 -1
  47. data/examples/rails3_root/config/initializers/rspec_generator.rb +0 -6
  48. data/examples/rails3_root/config/initializers/session_store.rb +0 -10
  49. data/examples/rails3_root/config/locales/en.yml +0 -5
  50. data/examples/rails3_root/config/routes.rb +0 -7
  51. data/examples/rails3_root/db/migrate/20090125013728_create_users.rb +0 -11
  52. data/examples/rails3_root/db/migrate/20090908054656_create_delayed_jobs.rb +0 -20
  53. data/examples/rails3_root/db/schema.rb +0 -33
  54. data/examples/rails3_root/db/seeds.rb +0 -7
  55. data/examples/rails3_root/doc/README_FOR_APP +0 -2
  56. data/examples/rails3_root/features/attachments.feature +0 -27
  57. data/examples/rails3_root/features/delayed_job.feature +0 -13
  58. data/examples/rails3_root/features/errors.feature +0 -40
  59. data/examples/rails3_root/features/example.feature +0 -93
  60. data/examples/rails3_root/features/step_definitions/user_steps.rb +0 -26
  61. data/examples/rails3_root/features/step_definitions/web_steps.rb +0 -219
  62. data/examples/rails3_root/features/support/env.rb +0 -58
  63. data/examples/rails3_root/features/support/env_ext.rb +0 -2
  64. data/examples/rails3_root/features/support/paths.rb +0 -33
  65. data/examples/rails3_root/lib/notifier_job.rb +0 -5
  66. data/examples/rails3_root/lib/tasks/cucumber.rake +0 -53
  67. data/examples/rails3_root/lib/tasks/rspec.rake +0 -69
  68. data/examples/rails3_root/public/404.html +0 -26
  69. data/examples/rails3_root/public/422.html +0 -26
  70. data/examples/rails3_root/public/500.html +0 -26
  71. data/examples/rails3_root/public/favicon.ico +0 -0
  72. data/examples/rails3_root/public/images/rails.png +0 -0
  73. data/examples/rails3_root/public/javascripts/application.js +0 -2
  74. data/examples/rails3_root/public/javascripts/controls.js +0 -965
  75. data/examples/rails3_root/public/javascripts/dragdrop.js +0 -974
  76. data/examples/rails3_root/public/javascripts/effects.js +0 -1123
  77. data/examples/rails3_root/public/javascripts/prototype.js +0 -4874
  78. data/examples/rails3_root/public/javascripts/rails.js +0 -109
  79. data/examples/rails3_root/public/robots.txt +0 -5
  80. data/examples/rails3_root/script/cucumber +0 -10
  81. data/examples/rails3_root/script/rails +0 -9
  82. data/examples/rails3_root/spec/controllers/welcome_controller_spec.rb +0 -20
  83. data/examples/rails3_root/spec/models/user_mailer_spec.rb +0 -47
  84. data/examples/rails3_root/spec/spec_helper.rb +0 -19
  85. data/examples/sinatra_root/config.ru +0 -4
  86. data/examples/sinatra_root/features/errors.feature +0 -40
  87. data/examples/sinatra_root/features/example.feature +0 -93
  88. data/examples/sinatra_root/features/step_definitions/user_steps.rb +0 -26
  89. data/examples/sinatra_root/features/step_definitions/web_steps.rb +0 -219
  90. data/examples/sinatra_root/features/support/env.rb +0 -21
  91. data/examples/sinatra_root/features/support/paths.rb +0 -29
  92. data/examples/sinatra_root/lib/example_sinatra_app.rb +0 -45
  93. data/install.rb +0 -0
  94. data/spec/email_spec/helpers_spec.rb +0 -220
  95. data/spec/email_spec/mail_ext_spec.rb +0 -34
  96. data/spec/email_spec/matchers_spec.rb +0 -486
  97. data/spec/spec_helper.rb +0 -16
@@ -1,109 +0,0 @@
1
- document.observe("dom:loaded", function() {
2
- var authToken = $$('meta[name=csrf-token]').first().readAttribute('content'),
3
- authParam = $$('meta[name=csrf-param]').first().readAttribute('content'),
4
- formTemplate = '<form method="#{method}" action="#{action}">\
5
- #{realmethod}<input name="#{param}" value="#{token}" type="hidden">\
6
- </form>',
7
- realmethodTemplate = '<input name="_method" value="#{method}" type="hidden">';
8
-
9
- function handleRemote(element) {
10
- var method, url, params;
11
-
12
- if (element.tagName.toLowerCase() == 'form') {
13
- method = element.readAttribute('method') || 'post';
14
- url = element.readAttribute('action');
15
- params = element.serialize(true);
16
- } else {
17
- method = element.readAttribute('data-method') || 'get';
18
- url = element.readAttribute('href');
19
- params = {};
20
- }
21
-
22
- var event = element.fire("ajax:before");
23
- if (event.stopped) return false;
24
-
25
- new Ajax.Request(url, {
26
- method: method,
27
- parameters: params,
28
- asynchronous: true,
29
- evalScripts: true,
30
-
31
- onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
32
- onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
33
- onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
34
- onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
35
- onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
36
- onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
37
- });
38
-
39
- element.fire("ajax:after");
40
- }
41
-
42
- $(document.body).observe("click", function(event) {
43
- var message = event.element().readAttribute('data-confirm');
44
- if (message && !confirm(message)) {
45
- event.stop();
46
- return false;
47
- }
48
-
49
- var element = event.findElement("a[data-remote=true]");
50
- if (element) {
51
- handleRemote(element);
52
- event.stop();
53
- }
54
-
55
- var element = event.findElement("a[data-method]");
56
- if (element && element.readAttribute('data-remote') != 'true') {
57
- var method = element.readAttribute('data-method'),
58
- piggyback = method.toLowerCase() != 'post',
59
- formHTML = formTemplate.interpolate({
60
- method: 'POST',
61
- realmethod: piggyback ? realmethodTemplate.interpolate({ method: method }) : '',
62
- action: element.readAttribute('href'),
63
- token: authToken,
64
- param: authParam
65
- });
66
-
67
- var form = new Element('div').update(formHTML).down().hide();
68
- this.insert({ bottom: form });
69
-
70
- form.submit();
71
- event.stop();
72
- }
73
- });
74
-
75
- // TODO: I don't think submit bubbles in IE
76
- $(document.body).observe("submit", function(event) {
77
- var message = event.element().readAttribute('data-confirm');
78
- if (message && !confirm(message)) {
79
- event.stop();
80
- return false;
81
- }
82
-
83
- var inputs = event.element().select("input[type=submit][data-disable-with]");
84
- inputs.each(function(input) {
85
- input.disabled = true;
86
- input.writeAttribute('data-original-value', input.value);
87
- input.value = input.readAttribute('data-disable-with');
88
- });
89
-
90
- var element = event.findElement("form[data-remote=true]");
91
- if (element) {
92
- handleRemote(element);
93
- event.stop();
94
- }
95
- });
96
-
97
- $(document.body).observe("ajax:complete", function(event) {
98
- var element = event.element();
99
-
100
- if (element.tagName.toLowerCase() == 'form') {
101
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
102
- inputs.each(function(input) {
103
- input.value = input.readAttribute('data-original-value');
104
- input.writeAttribute('data-original-value', null);
105
- input.disabled = false;
106
- });
107
- }
108
- });
109
- });
@@ -1,5 +0,0 @@
1
- # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
- #
3
- # To ban all spiders from the entire site uncomment the next two lines:
4
- # User-Agent: *
5
- # Disallow: /
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
- if vendored_cucumber_bin
5
- load File.expand_path(vendored_cucumber_bin)
6
- else
7
- require 'rubygems' unless ENV['NO_RUBYGEMS']
8
- require 'cucumber'
9
- load Cucumber::BINARY
10
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- ENV_PATH = File.expand_path('../../config/environment', __FILE__)
5
- BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
6
- APP_PATH = File.expand_path('../../config/application', __FILE__)
7
-
8
- require BOOT_PATH
9
- require 'rails/commands'
@@ -1,20 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe WelcomeController do
4
-
5
- describe "POST /signup (#signup)" do
6
- it "should deliver the signup email" do
7
- lambda {
8
- post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean"
9
- }.should change(ActionMailer::Base.deliveries, :size).by(1)
10
-
11
- last_delivery = ActionMailer::Base.deliveries.last
12
- last_delivery.to.should include "email@example.com"
13
- #message is now multipart, make sure both parts include Jimmy Bean
14
- last_delivery.parts[0].body.to_s.should include "Jimmy Bean"
15
- last_delivery.parts[1].body.to_s.should include "Jimmy Bean"
16
- end
17
-
18
- end
19
-
20
- end
@@ -1,47 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- # These two example groups are specifying the exact same behavior. However, the documentation style is different
4
- # and the value that each one provides is different with various trade-offs. Run these examples with the specdoc
5
- # formatter to get an idea of how they differ.
6
- # Example of documenting the behaviour explicitly and expressing the intent in the example's sentence.
7
- describe "Signup Email" do
8
- include EmailSpec::Helpers
9
- include EmailSpec::Matchers
10
- include ::Rails.application.routes.url_helpers
11
-
12
- subject { UserMailer.signup("jojo@yahoo.com", "Jojo Binks") }
13
-
14
- it "should be delivered to the email passed in" do
15
- should deliver_to("jojo@yahoo.com")
16
- end
17
-
18
- it "should contain the user's name in the mail body" do
19
- should have_body_text(/Jojo Binks/)
20
- end
21
-
22
- it "should contain a link to the confirmation page" do
23
- should have_body_text(/#{confirm_account_url(:host => 'example.com')}/)
24
- end
25
-
26
- it { should have_subject(/Account confirmation/) }
27
-
28
-
29
- end
30
-
31
- # In this example group more of the documentation is placed in the context trying to allow for more concise specs.
32
- describe "Signup Email" do
33
- include EmailSpec::Helpers
34
- include EmailSpec::Matchers
35
- include ::Rails.application.routes.url_helpers
36
-
37
- subject { UserMailer.signup("jojo@yahoo.com", "Jojo Binks") }
38
-
39
- it { should have_body_text(/#{confirm_account_url(:host => 'example.com')}/) }
40
- it { should have_subject(/Account confirmation/) }
41
-
42
- describe "sent with email address of 'jojo@yahoo.com', and users name 'Jojo Binks'" do
43
- subject { UserMailer.signup("jojo@yahoo.com", "Jojo Binks") }
44
- it { should deliver_to("jojo@yahoo.com") }
45
- it { should have_body_text(/Jojo Binks/) }
46
- end
47
- end
@@ -1,19 +0,0 @@
1
- # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
- # from the project root directory.
3
- ENV["RAILS_ENV"] ||= 'test'
4
- require File.dirname(__FILE__) + "/../config/environment"
5
- require 'rspec/rails'
6
-
7
- # Requires supporting files with custom matchers and macros, etc,
8
- # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
- RSpec.configure do |config|
11
- # == Mock Framework
12
- #
13
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
- #
15
- # config.mock_with :mocha
16
- # config.mock_with :flexmock
17
- # config.mock_with :rr
18
- config.mock_with :rspec
19
- end
@@ -1,4 +0,0 @@
1
- require 'rubygems'
2
- require File.join(File.dirname(__FILE__), 'lib/example_sinatra_app.rb')
3
-
4
- run ExampleSinatraApp
@@ -1,40 +0,0 @@
1
- Feature: Email-spec errors example
2
- In order to help alleviate email testing in apps
3
- As a email-spec contributor I a newcomer
4
- Should be able to easily determine where I have gone wrong
5
- These scenarios should fail with helpful messages
6
-
7
- Background:
8
- Given I am on the homepage
9
- And no emails have been sent
10
- When I fill in "Email" with "example@example.com"
11
- And I press "Sign up"
12
-
13
- Scenario: I fail to open an email with incorrect subject
14
- Then I should receive an email
15
- When "example@example.com" opens the email with subject "no email"
16
-
17
- Scenario: I fail to open an email with incorrect subject
18
- Then I should receive an email
19
- When "example@example.com" opens the email with subject /no email/
20
-
21
- Scenario: I fail to open an email with incorrect text
22
- Then I should receive an email
23
- When "example@example.com" opens the email with text "no email"
24
-
25
- Scenario: I fail to open an email with incorrect text
26
- Then I should receive an email
27
- When "example@example.com" opens the email with text /no email/
28
-
29
- Scenario: I fail to receive an email with the expected link
30
- Then I should receive an email
31
- When I open the email
32
- When I follow "link that doesn't exist" in the email
33
-
34
- Scenario: I attempt to operate on an email that is not opened
35
- Then I should receive an email
36
- When I follow "confirm" in the email
37
-
38
- Scenario: I attempt to check out an unopened email
39
- Then I should see "confirm" in the email body
40
- And I should see "Account confirmation" in the email subject
@@ -1,93 +0,0 @@
1
- Feature: EmailSpec Example -- Prevent Bots from creating accounts
2
-
3
- In order to help alleviate email testing in apps
4
- As an email-spec contributor I want new users of the library
5
- to easily adopt email-spec in their app by following this example
6
-
7
- In order to prevent bots from setting up new accounts
8
- As a site manager I want new users
9
- to verify their email address with a confirmation link
10
-
11
- Background:
12
- Given no emails have been sent
13
- And I am a real person wanting to sign up for an account
14
- And I am on the homepage
15
- And I submit my registration information
16
-
17
- Scenario: First person signup (as myself) with three ways of opening email
18
- Then I should receive an email
19
- And I should have 1 email
20
-
21
- # Opening email #1
22
- When I open the email
23
- Then I should see "Account confirmation" in the email subject
24
- And I should see "Joe Someone" in the email body
25
- And I should see "confirm" in the email body
26
-
27
- # Opening email #2
28
- When I open the email with subject "Account confirmation"
29
- Then I should see "Account confirmation" in the email subject
30
- And I should see "Joe Someone" in the email body
31
- And I should see "confirm" in the email body
32
-
33
- # Opening email #3
34
- When I open the email with subject /Account confirmation/
35
- Then I should see "Account confirmation" in the email subject
36
- And I should see "Joe Someone" in the email body
37
- And I should see "confirm" in the email body
38
-
39
- When I follow "Click here to confirm your account!" in the email
40
- Then I should see "Confirm your new account"
41
-
42
- And "foo@bar.com" should have no emails
43
-
44
- Scenario: Third person signup (emails sent to others) with three ways of opening email
45
- Then "foo@bar.com" should have no emails
46
- And "example@example.com" should receive an email
47
- And "example@example.com" should have 1 email
48
-
49
- # Opening email #1
50
- When they open the email
51
- Then they should see "Account confirmation" in the email subject
52
- And they should see "Joe Someone" in the email body
53
- And they should see "confirm" in the email body
54
-
55
- # Opening email #2
56
- When "example@example.com" opens the email with subject "Account confirmation"
57
- Then they should see "Account confirmation" in the email subject
58
- And they should see "Joe Someone" in the email body
59
- And they should see "confirm" in the email body
60
-
61
- # Opening email #3
62
- When "example@example.com" opens the email with subject /Account confirmation/
63
- Then they should see "Account confirmation" in the email subject
64
- And they should see "Joe Someone" in the email body
65
- And they should see "confirm" in the email body
66
-
67
- When they follow "Click here to confirm your account!" in the email
68
- Then they should see "Confirm your new account"
69
-
70
- Scenario: Declarative First Person signup
71
- Then I should receive an email with a link to a confirmation page
72
-
73
- Scenario: Declarative First Person signup
74
- Then they should receive an email with a link to a confirmation page
75
-
76
- Scenario: Checking for text in different parts
77
- Then I should receive an email
78
- And I should have 1 email
79
-
80
- # Opening email #1
81
- When I open the email
82
- Then I should see "This is the HTML part" in the email html part body
83
- And I should see "This is the text part" in the email text part body
84
-
85
- # Opening email #2
86
- When I open the email with text "This is the HTML part"
87
- Then I should see "This is the HTML part" in the email html part body
88
- And I should see "This is the text part" in the email text part body
89
-
90
- # Opening email #3
91
- When I open the email with text /This is the HTML part/
92
- Then I should see "This is the HTML part" in the email html part body
93
- And I should see "This is the text part" in the email text part body
@@ -1,26 +0,0 @@
1
- Given "I am a real person wanting to sign up for an account" do
2
- # no-op.. for documentation purposes only!
3
- end
4
-
5
- When /^I submit my registration information$/ do
6
- fill_in "Name", :with => 'Joe Someone'
7
- fill_in "Email", :with => 'example@example.com'
8
- click_button 'Sign up'
9
- end
10
-
11
- Then /^(?:I|they) should receive an email with a link to a confirmation page$/ do
12
- unread_emails_for(current_email_address).size.should == 1
13
-
14
- # this call will store the email and you can access it with current_email
15
- open_last_email_for(last_email_address)
16
- current_email.should have_subject(/Account confirmation/)
17
- current_email.should have_body_text('Joe Someone')
18
-
19
- click_email_link_matching /confirm/
20
- page.should have_content("Confirm your new account")
21
- end
22
-
23
- # Basically aliases "I should see [text]", but for third person
24
- Then /^they should see "([^\"]*)"$/ do |text|
25
- Then "I should see \"#{text}\""
26
- end
@@ -1,219 +0,0 @@
1
- # Taken from the cucumber-rails project.
2
- # IMPORTANT: This file is generated by cucumber-sinatra - edit at your own peril.
3
- # It is recommended to regenerate this file in the future when you upgrade to a
4
- # newer version of cucumber-sinatra. Consider adding your own code to a new file
5
- # instead of editing this one. Cucumber will automatically load all features/**/*.rb
6
- # files.
7
-
8
- require 'uri'
9
- require 'cgi'
10
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
11
-
12
- module WithinHelpers
13
- def with_scope(locator)
14
- locator ? within(locator) { yield } : yield
15
- end
16
- end
17
- World(WithinHelpers)
18
-
19
- Given /^(?:|I )am on (.+)$/ do |page_name|
20
- visit path_to(page_name)
21
- end
22
-
23
- When /^(?:|I )go to (.+)$/ do |page_name|
24
- visit path_to(page_name)
25
- end
26
-
27
- When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
28
- with_scope(selector) do
29
- click_button(button)
30
- end
31
- end
32
-
33
- When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
34
- with_scope(selector) do
35
- click_link(link)
36
- end
37
- end
38
-
39
- When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
40
- with_scope(selector) do
41
- fill_in(field, :with => value)
42
- end
43
- end
44
-
45
- When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
46
- with_scope(selector) do
47
- fill_in(field, :with => value)
48
- end
49
- end
50
-
51
- # Use this to fill in an entire form with data from a table. Example:
52
- #
53
- # When I fill in the following:
54
- # | Account Number | 5002 |
55
- # | Expiry date | 2009-11-01 |
56
- # | Note | Nice guy |
57
- # | Wants Email? | |
58
- #
59
- # TODO: Add support for checkbox, select og option
60
- # based on naming conventions.
61
- #
62
- When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields|
63
- with_scope(selector) do
64
- fields.rows_hash.each do |name, value|
65
- When %{I fill in "#{name}" with "#{value}"}
66
- end
67
- end
68
- end
69
-
70
- When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
71
- with_scope(selector) do
72
- select(value, :from => field)
73
- end
74
- end
75
-
76
- When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
77
- with_scope(selector) do
78
- check(field)
79
- end
80
- end
81
-
82
- When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
83
- with_scope(selector) do
84
- uncheck(field)
85
- end
86
- end
87
-
88
- When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
89
- with_scope(selector) do
90
- choose(field)
91
- end
92
- end
93
-
94
- When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
95
- with_scope(selector) do
96
- attach_file(field, path)
97
- end
98
- end
99
-
100
- Then /^(?:|I )should see JSON:$/ do |expected_json|
101
- require 'json'
102
- expected = JSON.pretty_generate(JSON.parse(expected_json))
103
- actual = JSON.pretty_generate(JSON.parse(response.body))
104
- expected.should == actual
105
- end
106
-
107
- Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
108
- with_scope(selector) do
109
- if page.respond_to? :should
110
- page.should have_content(text)
111
- else
112
- assert page.has_content?(text)
113
- end
114
- end
115
- end
116
-
117
- Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
118
- regexp = Regexp.new(regexp)
119
- with_scope(selector) do
120
- if page.respond_to? :should
121
- page.should have_xpath('//*', :text => regexp)
122
- else
123
- assert page.has_xpath?('//*', :text => regexp)
124
- end
125
- end
126
- end
127
-
128
- Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
129
- with_scope(selector) do
130
- if page.respond_to? :should
131
- page.should have_no_content(text)
132
- else
133
- assert page.has_no_content?(text)
134
- end
135
- end
136
- end
137
-
138
- Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
139
- regexp = Regexp.new(regexp)
140
- with_scope(selector) do
141
- if page.respond_to? :should
142
- page.should have_no_xpath('//*', :text => regexp)
143
- else
144
- assert page.has_no_xpath?('//*', :text => regexp)
145
- end
146
- end
147
- end
148
-
149
- Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
150
- with_scope(selector) do
151
- field = find_field(field)
152
- field_value = (field.tag_name == 'textarea') ? field.text : field.value
153
- if field_value.respond_to? :should
154
- field_value.should =~ /#{value}/
155
- else
156
- assert_match(/#{value}/, field_value)
157
- end
158
- end
159
- end
160
-
161
- Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
162
- with_scope(selector) do
163
- field = find_field(field)
164
- field_value = (field.tag_name == 'textarea') ? field.text : field.value
165
- if field_value.respond_to? :should_not
166
- field_value.should_not =~ /#{value}/
167
- else
168
- assert_no_match(/#{value}/, field_value)
169
- end
170
- end
171
- end
172
-
173
- Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
174
- with_scope(selector) do
175
- field_checked = find_field(label)['checked']
176
- if field_checked.respond_to? :should
177
- field_checked.should == 'checked'
178
- else
179
- assert_equal 'checked', field_checked
180
- end
181
- end
182
- end
183
-
184
- Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
185
- with_scope(selector) do
186
- field_checked = find_field(label)['checked']
187
- if field_checked.respond_to? :should_not
188
- field_checked.should_not == 'checked'
189
- else
190
- assert_not_equal 'checked', field_checked
191
- end
192
- end
193
- end
194
-
195
- Then /^(?:|I )should be on (.+)$/ do |page_name|
196
- current_path = URI.parse(current_url).path
197
- if current_path.respond_to? :should
198
- current_path.should == path_to(page_name)
199
- else
200
- assert_equal path_to(page_name), current_path
201
- end
202
- end
203
-
204
- Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
205
- query = URI.parse(current_url).query
206
- actual_params = query ? CGI.parse(query) : {}
207
- expected_params = {}
208
- expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209
-
210
- if actual_params.respond_to? :should
211
- actual_params.should == expected_params
212
- else
213
- assert_equal expected_params, actual_params
214
- end
215
- end
216
-
217
- Then /^show me the page$/ do
218
- save_and_open_page
219
- end