refinerycms-testing 1.0.11 → 2.0.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.
- data/.rspec +2 -1
- data/lib/generators/refinery/testing/templates/Guardfile +30 -0
- data/lib/generators/refinery/testing/templates/spec/spec_helper.rb +52 -0
- data/lib/generators/refinery/testing/testing_generator.rb +14 -0
- data/lib/refinery/tasks/testing.rake +51 -0
- data/lib/refinery/testing.rb +33 -0
- data/lib/refinery/testing/controller_macros.rb +8 -0
- data/lib/refinery/testing/controller_macros/authentication.rb +43 -0
- data/lib/refinery/testing/controller_macros/methods.rb +33 -0
- data/lib/refinery/testing/railtie.rb +31 -0
- data/lib/refinery/testing/request_macros.rb +7 -0
- data/lib/refinery/testing/request_macros/authentication.rb +63 -0
- data/lib/refinery/testing/url_helper.rb +9 -0
- data/lib/refinerycms-testing.rb +1 -50
- data/refinerycms-testing.gemspec +19 -51
- metadata +191 -169
- data/config/cucumber.yml +0 -11
- data/features/step_definitions/web_steps.rb +0 -227
- data/features/support/env.rb +0 -63
- data/features/support/factories.rb +0 -1
- data/features/support/negative_expectations_helper.rb +0 -57
- data/features/support/paths.rb +0 -92
- data/lib/gemspec.rb +0 -50
- data/lib/generators/refinerycms_testing_generator.rb +0 -28
- data/lib/generators/templates/features/support/paths.rb +0 -19
- data/lib/tasks/cucumber.rake +0 -53
- data/lib/tasks/rcov.rake +0 -47
- data/spec/rcov.opts +0 -2
- data/spec/spec_helper.rb +0 -83
- data/spec/support/refinery/controller_macros.rb +0 -27
data/config/cucumber.yml
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
<%
|
2
|
-
ENV["RAILS_ENV"] ||= "test"
|
3
|
-
require ::File.expand_path('../config/environment', __FILE__)
|
4
|
-
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
5
|
-
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
6
|
-
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip "
|
7
|
-
refinery_features = (::Refinery::Plugins.registered.pathnames << Rails.root).map{|p| p.join('features')}.reject{|d| !d.directory?}
|
8
|
-
%>
|
9
|
-
default: <%= std_opts %> <%= refinery_features.join(' ') %>
|
10
|
-
wip: --tags @wip:3 --wip features
|
11
|
-
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
@@ -1,227 +0,0 @@
|
|
1
|
-
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
-
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
-
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
-
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
-
# files.
|
6
|
-
|
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 be_true
|
178
|
-
else
|
179
|
-
assert 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
|
188
|
-
field_checked.should be_false
|
189
|
-
else
|
190
|
-
assert !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
|
-
path_to(page_name).should == current_path
|
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 /the page should have the css "(.*)"$/ do |expected_css|
|
218
|
-
page.should have_css(expected_css)
|
219
|
-
end
|
220
|
-
|
221
|
-
Then /^show me the page$/ do
|
222
|
-
save_and_open_page
|
223
|
-
end
|
224
|
-
|
225
|
-
Then /^output the page$/ do
|
226
|
-
puts page.body
|
227
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'refinerycms-base'
|
2
|
-
# IMPORTANT: This file is generated by cucumber-rails - 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-rails. 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
|
-
## This is custom functionality written by Refinery CMS.
|
9
|
-
def setup_environment
|
10
|
-
ENV["RAILS_ENV"] ||= "test"
|
11
|
-
ENV["RAILS_ROOT"] ||= Rails.root.to_s
|
12
|
-
|
13
|
-
if Refinery::WINDOWS
|
14
|
-
puts "Win32 users may experience cucumber/formatter/unicode errors. Requirement ommited, see: /features/support/env.rb to re-add."
|
15
|
-
else
|
16
|
-
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
17
|
-
end
|
18
|
-
require 'cucumber/rails'
|
19
|
-
|
20
|
-
require 'capybara/rails'
|
21
|
-
require 'capybara/cucumber'
|
22
|
-
require 'capybara/session'
|
23
|
-
|
24
|
-
include ::Devise::Controllers::UrlHelpers
|
25
|
-
|
26
|
-
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
27
|
-
# order to ease the transition to Capybara we set the default here. If you'd
|
28
|
-
# prefer to use XPath just remove this line and adjust any selectors in your
|
29
|
-
# steps to use the XPath syntax.
|
30
|
-
Capybara.default_selector = :css
|
31
|
-
end
|
32
|
-
|
33
|
-
def each_run
|
34
|
-
# If you set this to false, any error raised from within your app will bubble
|
35
|
-
# up to your step definition and out to cucumber unless you catch it somewhere
|
36
|
-
# on the way. You can make Rails rescue errors and render error pages on a
|
37
|
-
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
|
38
|
-
#
|
39
|
-
# If you set this to true, Rails will rescue all errors and render error
|
40
|
-
# pages, more or less in the same way your application would behave in the
|
41
|
-
# default production environment. It's not recommended to do this for all
|
42
|
-
# of your scenarios, as this makes it hard to discover errors in your application.
|
43
|
-
ActionController::Base.allow_rescue = false
|
44
|
-
|
45
|
-
require 'fileutils'
|
46
|
-
require 'rails/generators'
|
47
|
-
#require 'rails/generators/scripts/generate'
|
48
|
-
end
|
49
|
-
|
50
|
-
require 'rubygems'
|
51
|
-
# If spork is available in the Gemfile it'll be used but we don't force it.
|
52
|
-
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
|
53
|
-
Spork.prefork do
|
54
|
-
setup_environment
|
55
|
-
end
|
56
|
-
|
57
|
-
Spork.each_run do
|
58
|
-
each_run
|
59
|
-
end
|
60
|
-
else
|
61
|
-
setup_environment
|
62
|
-
each_run
|
63
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'factory_girl'
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# https://rspec.lighthouseapp.com/projects/16211/tickets/305
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module NegativeExpectationsHelper
|
5
|
-
|
6
|
-
class State
|
7
|
-
include Singleton
|
8
|
-
|
9
|
-
def is_negative?
|
10
|
-
@negative === true
|
11
|
-
end
|
12
|
-
|
13
|
-
def is_negative!
|
14
|
-
@negative = true
|
15
|
-
end
|
16
|
-
|
17
|
-
def restore!
|
18
|
-
@negative = false
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module ObjectExpectations
|
23
|
-
def self.included(base)
|
24
|
-
base.class_eval do
|
25
|
-
alias_method :original_should, :should
|
26
|
-
alias_method :original_should_not, :should_not
|
27
|
-
|
28
|
-
def should(*args, &block)
|
29
|
-
should_if_true(!State.instance.is_negative?, *args, &block)
|
30
|
-
end
|
31
|
-
|
32
|
-
def should_not(*args, &block)
|
33
|
-
should_if_true(State.instance.is_negative?, *args, &block)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private # ----------------------------------------------------------------
|
39
|
-
|
40
|
-
def should_if_true(cond, *args, &block)
|
41
|
-
cond ? self.send(:original_should, *args, &block) : self.send(:original_should_not, *args, &block)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def expect_opposite_if(cond)
|
46
|
-
raise "expected block" unless block_given?
|
47
|
-
State.instance.is_negative! if cond
|
48
|
-
yield
|
49
|
-
State.instance.restore! if cond
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class Object
|
54
|
-
include NegativeExpectationsHelper::ObjectExpectations
|
55
|
-
end
|
56
|
-
|
57
|
-
World(NegativeExpectationsHelper)
|
data/features/support/paths.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
([Rails.root] | ::Refinery::Plugins.registered.pathnames).map{|path|
|
2
|
-
path.join('features', 'support', 'paths.rb')
|
3
|
-
}.reject{|p| !p.exist?}.each do |paths|
|
4
|
-
require paths
|
5
|
-
end
|
6
|
-
|
7
|
-
module NavigationHelpers
|
8
|
-
# Loads in path_to functions from the engines that Refinery is using.
|
9
|
-
# They should look like this:
|
10
|
-
# module NavigationHelpers
|
11
|
-
# module Refinery
|
12
|
-
# module EngineName
|
13
|
-
# def path_to(page_name)
|
14
|
-
# case page_name
|
15
|
-
# when /regexp/
|
16
|
-
# some_path
|
17
|
-
# else
|
18
|
-
# nil
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
|
25
|
-
NavigationHelpers::Refinery.constants.each do |name|
|
26
|
-
begin
|
27
|
-
if (mod = "NavigationHelpers::Refinery::#{name}".constantize)
|
28
|
-
mod.module_eval %{alias :#{name.downcase}_path_to :path_to}
|
29
|
-
include mod
|
30
|
-
end
|
31
|
-
rescue
|
32
|
-
$stdout.puts $!.message
|
33
|
-
end
|
34
|
-
end if defined?(NavigationHelpers::Refinery)
|
35
|
-
# Maps a name to a path. Used by the
|
36
|
-
#
|
37
|
-
# When /^I go to (.+)$/ do |page_name|
|
38
|
-
#
|
39
|
-
# step definition in web_steps.rb
|
40
|
-
#
|
41
|
-
def path_to(page_name)
|
42
|
-
case page_name
|
43
|
-
|
44
|
-
when /the admin root/
|
45
|
-
admin_root_path
|
46
|
-
|
47
|
-
# Add more mappings here.
|
48
|
-
# Here is an example that pulls values out of the Regexp:
|
49
|
-
#
|
50
|
-
# when /^(.*)'s profile page$/i
|
51
|
-
# user_profile_path(User.find_by_username($1))
|
52
|
-
|
53
|
-
else
|
54
|
-
# Loads in path_to functions from the engines that Refinery is using.
|
55
|
-
# They should look like this:
|
56
|
-
# module NavigationHelpers
|
57
|
-
# module Refinery
|
58
|
-
# module EngineName
|
59
|
-
# def path_to(page_name)
|
60
|
-
# case page_name
|
61
|
-
# when /regexp/
|
62
|
-
# some_path
|
63
|
-
# else
|
64
|
-
# nil
|
65
|
-
# end
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
# end
|
70
|
-
NavigationHelpers::Refinery.constants.each do |name|
|
71
|
-
begin
|
72
|
-
if (path = self.send(:"#{name.downcase}_path_to", page_name)).present?
|
73
|
-
return path
|
74
|
-
end
|
75
|
-
rescue
|
76
|
-
$stdout.puts $!.message
|
77
|
-
end
|
78
|
-
end if defined?(NavigationHelpers::Refinery)
|
79
|
-
|
80
|
-
begin
|
81
|
-
page_name =~ /the (.*) page/
|
82
|
-
path_components = $1.split(/\s+/)
|
83
|
-
self.send(path_components.push('path').join('_').to_sym)
|
84
|
-
rescue Object => e
|
85
|
-
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
86
|
-
"Now, go and add a mapping in #{Rails.root.join('features', 'support', 'paths.rb')}"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
World(NavigationHelpers)
|