Updated

features/step_definitions / web_steps.rb

D
199 lines of codes
1 methods
205.8 complexity/method
7 churn
205.78 complexity
164 duplications
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. # It is recommended to regenerate this file in the future when you upgrade to a # newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. require 'uri' require 'cgi' require 'webmock/cucumber' require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) module WithinHelpers
  1. WithinHelpers has no descriptive comment
def with_scope(locator) locator ? within(locator) { yield } : yield end end World(WithinHelpers) Given /^(?:|I )am on (.+)$/ do |page_name| visit url_to(page_name) end When /^(?:|I )go to (.+)$/ do |page_name| visit url_to(page_name) end When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector| with_scope(selector) do click_button(button) end end When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| with_scope(selector) do click_link(link) end end When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector| with_scope(selector) do fill_in(field, :with => value) end end When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| with_scope(selector) do fill_in(field, :with => value) end end # Use this to fill in an entire form with data from a table. Example: # # When I fill in the following: # | Account Number | 5002 | # | Expiry date | 2009-11-01 | # | Note | Nice guy | # | Wants Email? | | # # TODO: Add support for checkbox, select og option # based on naming conventions. # When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields| with_scope(selector) do fields.rows_hash.each do |name, value| When %{I fill in "#{name}" with "#{value}"} end end end When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| with_scope(selector) do select(value, :from => field) end end When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| with_scope(selector) do check(field) end end When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| with_scope(selector) do uncheck(field) end end When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| with_scope(selector) do choose(field) end end When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector| with_scope(selector) do attach_file(field, path) end end Then /^(?:|I )should see JSON:$/ do |expected_json| require 'json' expected = JSON.pretty_generate(JSON.parse(expected_json)) actual = JSON.pretty_generate(JSON.parse(response.body)) expect(expected).to eq actual end Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| with_scope(selector) do expect(page).to have_content(text) end end Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
  1. Similar code found in 2 nodes Locations: 0 1
regexp = Regexp.new(regexp) with_scope(selector) do expect(page).to have_xpath('//*', :text => regexp) end end Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| with_scope(selector) do expect(page).to have_no_content(text) end end Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
  1. Similar code found in 2 nodes Locations: 0 1
regexp = Regexp.new(regexp) with_scope(selector) do expect(page).to have_no_xpath('//*', :text => regexp) end end Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
  1. Similar code found in 2 nodes Locations: 0 1
with_scope(selector) do field = find_field(field) field_value = (field.tag_name == 'textarea') ? field.text : field.value expect(field_value).to match(/#{value}/) end end Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
  1. Similar code found in 2 nodes Locations: 0 1
with_scope(selector) do field = find_field(field) field_value = (field.tag_name == 'textarea') ? field.text : field.value expect(field_value).not_to match(/#{value}/) end end Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
  1. Similar code found in 4 nodes Locations: 0 1 2 3
with_scope(selector) do field_checked = find_field(label)['checked'] expect(field_checked).to be_truthy end end Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
  1. Similar code found in 4 nodes Locations: 0 1 2 3
with_scope(selector) do field_checked = find_field(label)['checked'] expect(field_checked).to be_falsey end end Then /^the "([^"]*)" radio button(?: within "([^"]*)")? should be chosen$/ do |label, selector|
  1. Similar code found in 4 nodes Locations: 0 1 2 3
with_scope(selector) do field_checked = find_field(label)['checked'] expect(field_checked).to be_truthy end end Then /^the "([^"]*)" radio button(?: within "([^"]*)")? should not be chosen$/ do |label, selector|
  1. Similar code found in 4 nodes Locations: 0 1 2 3
with_scope(selector) do field_checked = find_field(label)['checked'] expect(field_checked).to be_falsey end end Then /^(?:|I )should be on (.+)$/ do |page_name| url = URI.parse(current_url) url.query = nil expect(url.to_s).to eq url_to(page_name) end Then /^(?:|I )should have the following query string:$/ do |expected_pairs| query = URI.parse(current_url).query actual_params = query ? CGI.parse(query) : {} expected_params = {} expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} expect(actual_params).to eq expected_params end Then(/^I should get a download with the filename "([^\"]*)"$/) do |filename| expect(page.response_headers['Content-Disposition']).to include("attachment; filename=#{filename}") end Then /^show me the page$/ do save_and_open_page end