Skip to content

Commit

Permalink
Improve and test "blabla should contain" steps. Rename features.
Browse files Browse the repository at this point in the history
  • Loading branch information
triskweline committed Aug 22, 2013
1 parent e4f3611 commit 96abd6b
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 11 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Marks scenario as pending
Print all sent emails to STDOUT.


* **Then that e?mail should have the following lines in the body:**
* **Then that e?mail should( not)? have the following lines in the body:**

Only works after you've retrieved the email using "Then an email should have been sent with:"

Expand Down Expand Up @@ -302,14 +302,21 @@ deprecation notice. Decide for yourself whether you want to use them:



* **Then the "..." field( within ...)? should contain "..."**
* **Then the "..." field should (not )?contain "..."**

Checks that an input field contains some value (allowing * as wildcard character)


* **Then the "..." field( within ...)? should not contain "..."**
* **Then I should see a form with the following values:**

Checks that a list of label/value pairs are visible as control inputs.

Example:

Then I should see a form with the following values:
| E-mail | foo@bar.com |
| Role | Administrator |



* **Then the "..." field should have the error "..."**
Expand Down Expand Up @@ -431,7 +438,7 @@ deprecation notice. Decide for yourself whether you want to use them:
Click on some text that might not be a link


* **Then "..." should link to "..."/**
* **Then "..." should link to "..."**

Use this step to check external links.

Expand Down Expand Up @@ -490,6 +497,11 @@ deprecation notice. Decide for yourself whether you want to use them:



* **When I switch to the new tab**




* **Then I should see in this order:?**

Checks that these strings are rendered in the given order in a single line or in multiple lines
Expand Down
2 changes: 1 addition & 1 deletion examples/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module NavigationHelpers
#
# When /^I go to (.+)$/ do |page_name|
#
# step definition in web_steps.rb
# step definition in web_steps.feature
#
def path_to(page_name)
case page_name
Expand Down
2 changes: 1 addition & 1 deletion examples/selectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module HtmlSelectorsHelpers
#
# When /^(.+) within (.+)$/ do |step, scope|
#
# step definitions in web_steps.rb
# step definitions in web_steps.feature
#
def selector_for(locator)
case locator
Expand Down
34 changes: 32 additions & 2 deletions lib/spreewald/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,43 @@
Then /^the "([^"]*)" field should (not )?contain "([^"]*)"$/ do |label, negate, expected_string|
patiently do
field = find_field(label)
field_value = ((field.tag_name == 'textarea') && field.text.present?) ? field.text.strip : field.value

field_value = case field.tag_name
when 'textarea'
field.text.present? ? field.text.strip : ''
when 'select'
options = field.all('option')
selected_option = options.detect(&:selected?) || options.first
if selected_option && selected_option.text.present?
selected_option.text.strip
else
''
end
else
field.value
end
field_value.send(negate ? :should_not : :should, contain_with_wildcards(expected_string))
end
end


# Checks that a list of label/value pairs are visible as control inputs.
#
# Example:
#
# Then I should see a form with the following values:
# | E-mail | foo@bar.com |
# | Role | Administrator |
#
Then /^I should see a form with the following values:$/ do |table|
expectations = table.raw
expectations.each do |label, expected_value|
step %(the "#{label}" field should contain "#{expected_value}")
end
end




# checks that an input field was wrapped with a validation error
Then /^the "([^"]*)" field should have the error "([^"]*)"$/ do |field, error_message|
patiently do
Expand Down
2 changes: 1 addition & 1 deletion lib/spreewald_support/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: UTF-8

module Spreewald
VERSION = "0.5.20"
VERSION = "0.6.0"
end
2 changes: 1 addition & 1 deletion tests/rails-2.3/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
spreewald (0.5.17)
spreewald (0.5.20)
capybara
cucumber
cucumber-rails
Expand Down
2 changes: 1 addition & 1 deletion tests/rails-3.2/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
spreewald (0.5.17)
spreewald (0.5.20)
capybara
cucumber
cucumber-rails
Expand Down
3 changes: 3 additions & 0 deletions tests/shared/app/controllers/forms_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class FormsController < ApplicationController

end
15 changes: 15 additions & 0 deletions tests/shared/app/views/forms/form1.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
= form_tag do

= label_tag 'text_control', 'Text control'
= text_field_tag 'text_control', 'Text control value'

= label_tag 'select_control', 'Select control'
= select_tag 'select_control', options_for_select([['Label 1', 'value1'], ['Label 2', 'value2'], ['Label 3', 'value3']], 'value2')

= label_tag 'select_control_without_selection', 'Select control without selection'
= select_tag 'select_control_without_selection', options_for_select([['Label 1', 'value1'], ['Label 2', 'value2'], ['Label 3', 'value3']])

= label_tag 'textarea_control', 'Textarea control'
= text_area_tag 'textarea_control', 'Textarea control value'


File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions tests/shared/features/shared/web_steps.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Web steps

Background:
When I go to "/forms/form1"

Scenario: /^the "([^"]*)" field should (not )?contain "([^"]*)"$/
Then the "Text control" field should contain "Text control value"
Then the "Select control" field should contain "Label 2"
Then the "Select control without selection" field should contain "Label 1"
Then the "Textarea control" field should contain "Textarea control value"

Scenario: /^I should see a form with the following values:$/
Then I should see a form with the following values:
| Text control | Text control value |
| Select control | Label 2 |
| Select control without selection | Label 1 |
| Textarea control | Textarea control value |

0 comments on commit 96abd6b

Please sign in to comment.