adva-core 0.0.9 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/section.rb +0 -6
- data/app/views/admin/sites/index.html.rb +2 -2
- data/config/redirects.rb +2 -1
- data/lib/adva.rb +41 -0
- data/lib/adva/controller/internal_redirect.rb +2 -1
- data/lib/adva/core.rb +8 -0
- data/lib/adva/engine.rb +1 -0
- data/lib/adva/generators/app.rb +7 -8
- data/lib/adva/generators/templates/app/Gemfile +4 -4
- data/lib/adva/generators/templates/app/Thorfile +9 -0
- data/lib/adva/generators/templates/app/app_template.rb +4 -2
- data/lib/adva/generators/templates/engine/Gemfile.erb +15 -0
- data/lib/adva/testing.rb +9 -2
- data/lib/adva/testing/engine.rb +1 -0
- data/lib/adva/view/form.rb +4 -1
- data/lib/adva_core/version.rb +1 -1
- data/lib/bundler/repository.rb +117 -0
- data/lib/patches/inherited_resources.rb +4 -3
- data/lib/patches/rails/integretion_runner_respond_to.rb +1 -1
- data/lib/patches/rails/polymorphic_url_for.rb +3 -1
- data/lib/patches/rails/recognize_path_env.rb +33 -29
- data/lib/patches/rails/route_set_to_param.rb +19 -17
- data/lib/patches/rails/route_set_trailing_segment.rb +1 -1
- data/lib/patches/rails/sti_associations.rb +10 -4
- data/lib/patches/rails/translation_helper.rb +2 -1
- data/lib/patches/responders/flash_responder.rb +1 -0
- data/lib/patches/simple_form.rb +2 -2
- data/lib/testing/env.rb +19 -13
- data/lib/testing/factories.rb +5 -1
- data/lib/testing/paths.rb +4 -4
- data/lib/testing/selectors.rb +72 -0
- data/lib/testing/step_definitions/capybara_steps.rb +211 -0
- data/lib/testing/step_definitions/common_steps.rb +87 -98
- data/lib/testing/step_definitions/debug_steps.rb +11 -4
- data/lib/testing/step_definitions/email_steps.rb +195 -0
- data/lib/testing/step_definitions/menu_steps.rb +7 -2
- data/lib/testing/step_definitions/more_web_steps.rb +4 -0
- data/lib/testing/step_definitions/pickle_steps.rb +104 -0
- data/lib/testing/step_definitions/transforms.rb +10 -1
- data/lib/testing/support/pickle.rb +24 -0
- data/public/javascripts/adva-core/jquery/jquery.table_tree.js +5 -1
- metadata +340 -305
- data/lib/patches/rails/asset_expansion_multiple_registrations.rb +0 -21
- data/lib/patches/rails/template_resolver_caching.rb +0 -9
- data/lib/patches/webrat/links-data-method.rb +0 -15
- data/lib/patches/webrat/logger.rb +0 -14
- data/lib/patches/webrat/upload_file.rb +0 -23
- data/lib/patches/webrat/within_xpath.rb +0 -13
- data/lib/testing/step_definitions/webrat_steps.rb +0 -284
- data/lib/testing/step_definitions/within_steps.rb +0 -16
@@ -1,41 +1,45 @@
|
|
1
|
-
require 'action_dispatch/routing/mapper'
|
2
|
-
require 'action_dispatch/routing/route_set'
|
3
|
-
|
4
1
|
# make recognize_path pass the given environment through
|
2
|
+
#
|
3
|
+
# FIXME: patch this better, do not override the whole method
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def recognize_path(path, environment = {})
|
10
|
-
method = (environment[:method] || "GET").to_s.upcase
|
11
|
-
path = Rack::Mount::Utils.normalize_path(path)
|
5
|
+
Gem.patching('rails', '3.0.9') do
|
6
|
+
require 'action_dispatch/routing/mapper'
|
7
|
+
require 'action_dispatch/routing/route_set'
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
module ActionDispatch
|
10
|
+
module Routing
|
11
|
+
class RouteSet
|
12
|
+
def recognize_path(path, environment = {})
|
13
|
+
method = (environment[:method] || "GET").to_s.upcase
|
14
|
+
path = Rack::Mount::Utils.normalize_path(path)
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
params[key] = URI.unescape(value)
|
26
|
-
end
|
16
|
+
begin
|
17
|
+
# env = Rack::MockRequest.env_for(path, {:method => method})
|
18
|
+
env = Rack::MockRequest.env_for(path, {:method => method}).merge(environment)
|
19
|
+
rescue URI::InvalidURIError => e
|
20
|
+
raise ActionController::RoutingError, e.message
|
27
21
|
end
|
28
22
|
|
29
|
-
|
30
|
-
|
23
|
+
req = Rack::Request.new(env)
|
24
|
+
@set.recognize(req) do |route, matches, params|
|
25
|
+
params.each do |key, value|
|
26
|
+
if value.is_a?(String)
|
27
|
+
value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware?
|
28
|
+
params[key] = URI.unescape(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
dispatcher = route.app
|
33
|
+
dispatcher = dispatcher.app while dispatcher.is_a?(Mapper::Constraints)
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
|
36
|
+
dispatcher.prepare_params!(params)
|
37
|
+
return params
|
38
|
+
end
|
35
39
|
end
|
36
|
-
end
|
37
40
|
|
38
|
-
|
41
|
+
raise ActionController::RoutingError, "No route matches #{path.inspect}"
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -2,24 +2,26 @@
|
|
2
2
|
# if arity allows it. so we can use param names in routes and distinguish them
|
3
3
|
# in the model.
|
4
4
|
|
5
|
-
|
5
|
+
Gem.patching('rails', '3.0.9') do
|
6
|
+
require 'action_dispatch/routing/route_set'
|
6
7
|
|
7
|
-
ActionDispatch::Routing::RouteSet::Generator.class_eval do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
ActionDispatch::Routing::RouteSet::Generator.class_eval do
|
9
|
+
def opts
|
10
|
+
parameterize = lambda do |name, value|
|
11
|
+
if name == :controller
|
12
|
+
value
|
13
|
+
elsif value.is_a?(Array)
|
14
|
+
value.map { |v| Rack::Mount::Utils.escape_uri(to_param(name, v)) }.join('/')
|
15
|
+
else
|
16
|
+
return nil unless param = to_param(name, value)
|
17
|
+
param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/")
|
18
|
+
end
|
17
19
|
end
|
20
|
+
{:parameterize => parameterize}
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_param(name, value)
|
24
|
+
value.method(:to_param).arity == 0 ? value.to_param : value.to_param(name)
|
18
25
|
end
|
19
|
-
{:parameterize => parameterize}
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_param(name, value)
|
23
|
-
value.method(:to_param).arity == 1 ? value.to_param(name) : value.to_param
|
24
26
|
end
|
25
|
-
end
|
27
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'gem-patching'
|
2
2
|
|
3
3
|
# remove trailing segments '.1' and query params '?=1' from url
|
4
|
-
Gem.patching('rails', '3.0.
|
4
|
+
Gem.patching('rails', '3.0.9') do
|
5
5
|
ActionDispatch::Routing::RouteSet.class_eval do
|
6
6
|
def url_for_with_singleton_resource_patch(options)
|
7
7
|
url_for_without_singleton_resource_patch(options).
|
@@ -4,13 +4,19 @@ require 'gem-patching'
|
|
4
4
|
# i.e.: site.sections.build(:type => 'Page').class == Page
|
5
5
|
# http://pragmatig.com/2010/06/04/fixing-rails-nested-attributes-on-collections-with-sti
|
6
6
|
|
7
|
-
Gem.patching('rails', '3.0.
|
7
|
+
Gem.patching('rails', '3.0.9') do
|
8
8
|
class ActiveRecord::Reflection::AssociationReflection
|
9
|
-
def build_association(*options)
|
9
|
+
def build_association(*options, &block)
|
10
10
|
if options.first.is_a?(Hash) && options.first[:type].present?
|
11
|
-
options.first[:type].to_s.constantize
|
11
|
+
requested_class = options.first[:type].to_s.constantize
|
12
|
+
if requested_class <= klass
|
13
|
+
requested_class.new(*options, &block)
|
14
|
+
else
|
15
|
+
# do not allow to create random record, for example User with role admin
|
16
|
+
raise "cannot build associated record: #{requested_class} does not inherit from #{klass}"
|
17
|
+
end
|
12
18
|
else
|
13
|
-
klass.new(*options)
|
19
|
+
klass.new(*options,&block)
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
@@ -2,7 +2,8 @@
|
|
2
2
|
# of rescuing exceptions itself.
|
3
3
|
#
|
4
4
|
# See https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5969-bump-i18n-and-make-translationhelper-use-new-rescue_format-option#ticket-5969-8
|
5
|
-
|
5
|
+
# can be removed in 3.1
|
6
|
+
Gem.patching('rails', '3.0.9') do
|
6
7
|
ActionView::Helpers::TranslationHelper.module_eval do
|
7
8
|
def translate(key, options = {})
|
8
9
|
options.merge!(:rescue_format => :html) unless options.key?(:rescue_format)
|
data/lib/patches/simple_form.rb
CHANGED
@@ -2,7 +2,7 @@ require 'gem-patching'
|
|
2
2
|
|
3
3
|
# add "blog edit_blog" as css classes. should propose a patch to simple_form
|
4
4
|
|
5
|
-
Gem.patching('simple_form', '1.
|
5
|
+
Gem.patching('simple_form', '1.3.1') do
|
6
6
|
SimpleForm::ActionViewExtensions::FormHelper.module_eval do
|
7
7
|
[:form_for, :fields_for, :remote_form_for].each do |helper|
|
8
8
|
class_eval <<-METHOD, __FILE__, __LINE__
|
@@ -34,4 +34,4 @@ Gem.patching('simple_form', '1.2.2') do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
data/lib/testing/env.rb
CHANGED
@@ -7,16 +7,8 @@ name = "#{File.basename(Dir.pwd)}-test"
|
|
7
7
|
app = Adva::Generators::App.new(name, :target => '/tmp', :migrate => true)
|
8
8
|
app.invoke
|
9
9
|
|
10
|
-
Gem.patching('webrat', '0.7.2') do
|
11
|
-
ActionController.send(:remove_const, :AbstractRequest)
|
12
|
-
end
|
13
|
-
|
14
10
|
require 'cucumber/rails/world'
|
15
|
-
require 'cucumber/rails/active_record'
|
16
11
|
require 'cucumber/web/tableish'
|
17
|
-
require 'webrat'
|
18
|
-
require 'webrat/core/matchers'
|
19
|
-
require 'patches/webrat/logger'
|
20
12
|
require 'test/unit/assertions'
|
21
13
|
require 'action_dispatch/testing/assertions'
|
22
14
|
require 'factory_girl'
|
@@ -27,13 +19,27 @@ Adva::Testing.load_cucumber_support
|
|
27
19
|
Adva::Testing.load_assertions
|
28
20
|
Adva::Testing.load_helpers
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
require 'capybara/rails'
|
23
|
+
require 'capybara/cucumber'
|
24
|
+
Capybara.default_selector = :css
|
25
|
+
Capybara.default_wait_time = 5
|
26
|
+
World(Capybara)
|
27
|
+
|
28
|
+
|
29
|
+
require 'database_cleaner'
|
30
|
+
require 'database_cleaner/cucumber'
|
31
|
+
DatabaseCleaner.strategy = :transaction
|
32
|
+
DatabaseCleaner.clean_with :truncation
|
33
|
+
|
34
|
+
# Fix undefined method `add_assertion' for nil:NilClass for all assertions
|
35
|
+
# https://github.com/aslakhellesoy/cucumber-rails/issues/97
|
36
|
+
if RUBY_VERSION =~ /1.8/
|
37
|
+
require 'test/unit/testresult'
|
38
|
+
Test::Unit.run = true
|
33
39
|
end
|
34
40
|
|
35
|
-
ActionController::Base.allow_rescue = false
|
36
|
-
Cucumber::Rails::World.use_transactional_fixtures = true
|
41
|
+
#ActionController::Base.allow_rescue = false
|
42
|
+
#Cucumber::Rails::World.use_transactional_fixtures = true
|
37
43
|
Rails.backtrace_cleaner.remove_silencers!
|
38
44
|
|
39
45
|
World(GlobalHelpers)
|
data/lib/testing/factories.rb
CHANGED
data/lib/testing/paths.rb
CHANGED
@@ -27,7 +27,7 @@ module Adva::Core::Paths
|
|
27
27
|
polymorphic_path([:admin, :sites])
|
28
28
|
|
29
29
|
when /^the admin dashboard page$/
|
30
|
-
site = Site.first
|
30
|
+
site = Site.first || raise("no site found")
|
31
31
|
polymorphic_path([:admin, site])
|
32
32
|
|
33
33
|
when /^the admin dashboard page for the site on "([^"]*)"$/
|
@@ -35,16 +35,16 @@ module Adva::Core::Paths
|
|
35
35
|
polymorphic_path([:admin, site])
|
36
36
|
|
37
37
|
when /^the admin sections page$/
|
38
|
-
site = Site.first
|
38
|
+
site = Site.first || raise("no site found")
|
39
39
|
polymorphic_path([:admin, site, :sections])
|
40
40
|
|
41
41
|
when /^the admin "([^"]*)" section page$/
|
42
|
-
site = Site.first
|
42
|
+
site = Site.first || raise("no site found")
|
43
43
|
section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
|
44
44
|
polymorphic_path([:admin, site, section])
|
45
45
|
|
46
46
|
when /^the admin "([^"]*)" section settings page$/
|
47
|
-
site = Site.first
|
47
|
+
site = Site.first || raise("no site found")
|
48
48
|
section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
|
49
49
|
polymorphic_path([:edit, :admin, site, section])
|
50
50
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module HtmlSelectorsHelpers
|
2
|
+
# Maps a name to a selector. Used primarily by the
|
3
|
+
#
|
4
|
+
# When /^(.+) within (.+)$/ do |step, scope|
|
5
|
+
#
|
6
|
+
# step definitions in web_steps.rb
|
7
|
+
#
|
8
|
+
Word = /[a-z_\-]+/
|
9
|
+
def selector_for(locator)
|
10
|
+
case locator
|
11
|
+
|
12
|
+
when /the page/
|
13
|
+
"html > body"
|
14
|
+
|
15
|
+
when /([a-z ]+) form/
|
16
|
+
name = $1.gsub(' ', '_') #.gsub(/edit_/, '')
|
17
|
+
"form.#{name}, form##{name}"
|
18
|
+
|
19
|
+
# I follow "View" within the "Blog" row
|
20
|
+
# ^^^^^^^^^^^^^^
|
21
|
+
# selects the rows in which the given text shows up
|
22
|
+
when /the "([^"]*)" row/
|
23
|
+
having_text = %Q~contains( text(), "#{$1}")~
|
24
|
+
row = "//table//tr[ descendant::*[#{having_text}] ]"
|
25
|
+
[:xpath, row]
|
26
|
+
|
27
|
+
# I should see "Categories" within tabs
|
28
|
+
# ^^^^
|
29
|
+
when /^(?:a?n )?(#{Word})$/
|
30
|
+
".#{$1}"
|
31
|
+
|
32
|
+
when 'the title'
|
33
|
+
"h1,h2,h3"
|
34
|
+
|
35
|
+
when 'the top menu'
|
36
|
+
"#top"
|
37
|
+
|
38
|
+
when 'the main menu'
|
39
|
+
"ul.main.menu"
|
40
|
+
|
41
|
+
when /^the actions? menu$/
|
42
|
+
"#actions"
|
43
|
+
|
44
|
+
when /^the (#{Word})$/
|
45
|
+
"##{$1}"
|
46
|
+
|
47
|
+
# Add more mappings here.
|
48
|
+
# Here is an example that pulls values out of the Regexp:
|
49
|
+
#
|
50
|
+
# when /the (notice|error|info) flash/
|
51
|
+
# ".flash.#{$1}"
|
52
|
+
|
53
|
+
# You can also return an array to use a different selector
|
54
|
+
# type, like:
|
55
|
+
#
|
56
|
+
# when /the header/
|
57
|
+
# [:xpath, "//header"]
|
58
|
+
|
59
|
+
# This allows you to provide a quoted selector as the scope
|
60
|
+
# for "within" steps as was previously the default for the
|
61
|
+
# web steps:
|
62
|
+
when /"(.+)"/
|
63
|
+
$1
|
64
|
+
|
65
|
+
else
|
66
|
+
raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
|
67
|
+
"Now, go and add a mapping in #{__FILE__}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
World(HtmlSelectorsHelpers)
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# TL;DR: YOU SHOULD DELETE THIS FILE
|
2
|
+
#
|
3
|
+
# This file iwas generated by Cucumber-Rails and is only here to get you a head start
|
4
|
+
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
|
5
|
+
# visit pages, interact with widgets and make assertions about page content.
|
6
|
+
#
|
7
|
+
# If you use these step definitions as basis for your features you will quickly end up
|
8
|
+
# with features that are:
|
9
|
+
#
|
10
|
+
# * Hard to maintain
|
11
|
+
# * Verbose to read
|
12
|
+
#
|
13
|
+
# A much better approach is to write your own higher level step definitions, following
|
14
|
+
# the advice in the following blog posts:
|
15
|
+
#
|
16
|
+
# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
|
17
|
+
# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
|
18
|
+
# * http://elabs.se/blog/15-you-re-cuking-it-wrong
|
19
|
+
#
|
20
|
+
|
21
|
+
|
22
|
+
require 'uri'
|
23
|
+
require 'cgi'
|
24
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "paths"))
|
25
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "selectors"))
|
26
|
+
|
27
|
+
module WithinHelpers
|
28
|
+
def with_scope(locator)
|
29
|
+
locator ? within(*selector_for(locator)) { yield } : yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
World(WithinHelpers)
|
33
|
+
|
34
|
+
# Single-line step scoper
|
35
|
+
When /^(.*) within ([^:]+)$/ do |step, parent|
|
36
|
+
with_scope(parent) { When step }
|
37
|
+
end
|
38
|
+
|
39
|
+
# Multi-line step scoper
|
40
|
+
When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
|
41
|
+
with_scope(parent) { When "#{step}:", table_or_string }
|
42
|
+
end
|
43
|
+
|
44
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
45
|
+
visit path_to(page_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
49
|
+
visit path_to(page_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
When /^(?:|I )press "([^"]*)"$/ do |button|
|
53
|
+
click_button(button)
|
54
|
+
end
|
55
|
+
|
56
|
+
When /^(?:|I )follow "([^"]*)"$/ do |link|
|
57
|
+
click_link(link)
|
58
|
+
end
|
59
|
+
|
60
|
+
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
61
|
+
fill_in(field, :with => value)
|
62
|
+
end
|
63
|
+
|
64
|
+
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
|
65
|
+
fill_in(field, :with => value)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Use this to fill in an entire form with data from a table. Example:
|
69
|
+
#
|
70
|
+
# When I fill in the following:
|
71
|
+
# | Account Number | 5002 |
|
72
|
+
# | Expiry date | 2009-11-01 |
|
73
|
+
# | Note | Nice guy |
|
74
|
+
# | Wants Email? | |
|
75
|
+
#
|
76
|
+
# TODO: Add support for checkbox, select og option
|
77
|
+
# based on naming conventions.
|
78
|
+
#
|
79
|
+
When /^(?:|I )fill in the following:$/ do |fields|
|
80
|
+
fields.rows_hash.each do |name, value|
|
81
|
+
When %{I fill in "#{name}" with "#{value}"}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
86
|
+
select(value, :from => field)
|
87
|
+
end
|
88
|
+
|
89
|
+
When /^(?:|I )check "([^"]*)"$/ do |field|
|
90
|
+
check(field)
|
91
|
+
end
|
92
|
+
|
93
|
+
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
94
|
+
uncheck(field)
|
95
|
+
end
|
96
|
+
|
97
|
+
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
98
|
+
choose(field)
|
99
|
+
end
|
100
|
+
|
101
|
+
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
102
|
+
attach_file(field, File.expand_path(path))
|
103
|
+
end
|
104
|
+
|
105
|
+
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
106
|
+
if page.respond_to? :should
|
107
|
+
page.should have_content(text)
|
108
|
+
else
|
109
|
+
assert page.has_content?(text)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
114
|
+
regexp = Regexp.new(regexp)
|
115
|
+
|
116
|
+
if page.respond_to? :should
|
117
|
+
page.should have_xpath('//*', :text => regexp)
|
118
|
+
else
|
119
|
+
assert page.has_xpath?('//*', :text => regexp)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
124
|
+
if page.respond_to? :should
|
125
|
+
page.should have_no_content(text)
|
126
|
+
else
|
127
|
+
assert page.has_no_content?(text)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
132
|
+
regexp = Regexp.new(regexp)
|
133
|
+
|
134
|
+
if page.respond_to? :should
|
135
|
+
page.should have_no_xpath('//*', :text => regexp)
|
136
|
+
else
|
137
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
142
|
+
with_scope(parent) do
|
143
|
+
field = find_field(field)
|
144
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
145
|
+
if field_value.respond_to? :should
|
146
|
+
field_value.should =~ /#{value}/
|
147
|
+
else
|
148
|
+
assert_match(/#{value}/, field_value)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
154
|
+
with_scope(parent) do
|
155
|
+
field = find_field(field)
|
156
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
157
|
+
if field_value.respond_to? :should_not
|
158
|
+
field_value.should_not =~ /#{value}/
|
159
|
+
else
|
160
|
+
assert_no_match(/#{value}/, field_value)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
166
|
+
with_scope(parent) do
|
167
|
+
field_checked = find_field(label)['checked']
|
168
|
+
if field_checked.respond_to? :should
|
169
|
+
field_checked.should be_true
|
170
|
+
else
|
171
|
+
assert field_checked
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
177
|
+
with_scope(parent) do
|
178
|
+
field_checked = find_field(label)['checked']
|
179
|
+
if field_checked.respond_to? :should
|
180
|
+
field_checked.should be_false
|
181
|
+
else
|
182
|
+
assert !field_checked
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
188
|
+
current_path = URI.parse(current_url).path
|
189
|
+
if current_path.respond_to? :should
|
190
|
+
current_path.should == path_to(page_name)
|
191
|
+
else
|
192
|
+
assert_equal path_to(page_name), current_path
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
197
|
+
query = URI.parse(current_url).query
|
198
|
+
actual_params = query ? CGI.parse(query) : {}
|
199
|
+
expected_params = {}
|
200
|
+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
201
|
+
|
202
|
+
if actual_params.respond_to? :should
|
203
|
+
actual_params.should == expected_params
|
204
|
+
else
|
205
|
+
assert_equal expected_params, actual_params
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
Then /^show me the page$/ do
|
210
|
+
save_and_open_page
|
211
|
+
end
|