lib/spreewald/web_steps.rb in spreewald-1.11.4 vs lib/spreewald/web_steps.rb in spreewald-1.11.5
- old
+ new
@@ -41,13 +41,13 @@
# Example:
#
# Then I should see "some text" within ".page_body"
When /^(.*) within (.*[^:])$/ do |nested_step, parent|
selector = _selector_for(parent)
- if selector.is_a?(String) # could also be a Capybara::Node::Element
+ if selector.is_a?(String) || selector.is_a?(Array) # could also be a Capybara::Node::Element
patiently do
- page.should have_css(selector)
+ page.should have_selector(*selector)
end
end
patiently do
with_scope(parent) { step(nested_step) }
end
@@ -274,15 +274,19 @@
classes.should_not include('field_with_errors')
classes.should_not include('error')
end
end.overridable
-Then /^the "([^"]*)" checkbox should( not)? be checked$/ do |label, negate|
+Then /^the "([^"]*)" checkbox should( not)? be checked( and disabled)?$/ do |label, negate, disabled|
expectation = negate ? :should_not : :should
patiently do
- field = find_field(label)
+ field = if Capybara::VERSION < "2.1"
+ find_field(label)
+ else
+ find_field(label, :disabled => !!disabled)
+ end
field.send expectation, be_checked
end
end.overridable
Then /^the radio button "([^"]*)" should( not)? be (?:checked|selected)$/ do |field, negate|
@@ -376,19 +380,23 @@
end
end.overridable
# Checks for the presence of an option in a select
Then /^"([^"]*)" should( not)? be an option for "([^"]*)"$/ do |value, negate, field|
+ finder_arguments = if Capybara::VERSION < "2.12"
+ ['option', { :text => value }]
+ else
+ ['option', { :exact_text => value }]
+ end
patiently do
- xpath = ".//option[text() = '#{value}']"
if negate
begin
- field_labeled(field).find(:xpath, xpath).should_not be_present
+ field_labeled(field).should have_no_css(*finder_arguments)
rescue Capybara::ElementNotFound
end
else
- field_labeled(field).find(:xpath, xpath).should be_present
+ field_labeled(field).should have_css(*finder_arguments)
end
end
end.overridable
# Like `Then I should see`, but with single instead of double quotes. In case
@@ -495,11 +503,11 @@
#
# When I click on the element for the sidebar
When /^I click on the element for (.+?)$/ do |locator|
patiently do
selector = _selector_for(locator)
- page.find(selector).click
+ page.find(*selector).click
end
end.overridable
# Use this step to check external links.
#
@@ -542,11 +550,11 @@
# Then I should not see the element for the sidebar
Then /^I should (not )?see (?:an|the) element for (.*?)$/ do |negate, locator|
expectation = negate ? :should_not : :should
selector = _selector_for(locator)
patiently do
- page.send(expectation, have_css(selector))
+ page.send(expectation, have_selector(*selector))
end
end.overridable
# Checks that the result has content type `text/plain`
@@ -630,12 +638,16 @@
page.text.gsub(/\s+/, ' ').should =~ pattern
end
end.overridable
# Tests that an input or button with the given label is disabled.
-Then /^the "([^\"]*)" (field|button) should( not)? be disabled$/ do |label, kind, negate|
- if kind == 'field'
- element = find_field(label)
+Then /^the "([^\"]*)" (field|button|checkbox) should( not)? be disabled$/ do |label, kind, negate|
+ if kind == 'field' || kind == 'checkbox'
+ if Capybara::VERSION < "2.1"
+ element = find_field(label, :disabled => !negate)
+ else
+ element = find_field(label, :disabled => !negate)
+ end
else
element = find_button(label)
end
["false", "", nil].send(negate ? :should : :should_not, include(element[:disabled]))
end.overridable