rspec-rails 1.3.4 → 2.0.0.a2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -7
- data/README.markdown +58 -0
- data/Rakefile +51 -9
- data/example_app_template.rb +33 -0
- data/lib/generators/rspec.rb +25 -0
- data/lib/generators/rspec/controller/controller_generator.rb +26 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +15 -0
- data/lib/generators/rspec/controller/templates/view_spec.rb +12 -0
- data/lib/generators/rspec/helper/helper_generator.rb +11 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +14 -0
- data/lib/generators/rspec/install/install_generator.rb +29 -0
- data/lib/generators/rspec/install/templates/lib/tasks/rspec.rake +119 -0
- data/lib/generators/rspec/install/templates/script/rspec.tt +4 -0
- data/{generators/rspec/templates → lib/generators/rspec/install/templates/spec}/rcov.opts +0 -0
- data/{generators/rspec/templates → lib/generators/rspec/install/templates/spec}/spec.opts +0 -0
- data/{generators/rspec/templates → lib/generators/rspec/install/templates/spec}/spec_helper.rb +14 -12
- data/lib/generators/rspec/integration/integration_generator.rb +12 -0
- data/{generators/integration_spec/templates/integration_spec.rb → lib/generators/rspec/integration/templates/request_spec.rb} +0 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +21 -0
- data/lib/generators/rspec/mailer/templates/fixture +3 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +14 -0
- data/lib/generators/rspec/model/model_generator.rb +22 -0
- data/lib/generators/rspec/model/templates/fixtures.yml +19 -0
- data/{generators/rspec_model → lib/generators/rspec/model}/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/observer/observer_generator.rb +12 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +5 -0
- data/lib/generators/rspec/plugin/plugin_generator.rb +11 -0
- data/lib/generators/rspec/plugin/templates/%file_name%_spec.rb.tt +5 -0
- data/lib/generators/rspec/plugin/templates/test_helper.rb +5 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +112 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +127 -0
- data/{generators/rspec_scaffold/templates/edit_erb_spec.rb → lib/generators/rspec/scaffold/templates/edit_spec.rb} +3 -3
- data/{generators/rspec_scaffold/templates/index_erb_spec.rb → lib/generators/rspec/scaffold/templates/index_spec.rb} +4 -4
- data/{generators/rspec_scaffold/templates/new_erb_spec.rb → lib/generators/rspec/scaffold/templates/new_spec.rb} +3 -3
- data/{generators/rspec_scaffold → lib/generators/rspec/scaffold}/templates/routing_spec.rb +4 -0
- data/{generators/rspec_scaffold/templates/show_erb_spec.rb → lib/generators/rspec/scaffold/templates/show_spec.rb} +4 -4
- data/lib/rspec/rails.rb +2 -0
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/example/controller_example_group.rb +31 -0
- data/lib/rspec/rails/example/request_example_group.rb +26 -0
- data/lib/rspec/rails/matchers.rb +14 -0
- data/lib/rspec/rails/transactional_database_support.rb +38 -0
- data/lib/rspec/rails/version.rb +16 -0
- data/rspec-rails.gemspec +78 -18
- metadata +97 -321
- data/.document +0 -7
- data/Contribute.rdoc +0 -4
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -27
- data/History.rdoc +0 -321
- data/License.txt +0 -33
- data/Manifest.txt +0 -165
- data/README.rdoc +0 -48
- data/TODO.txt +0 -17
- data/Upgrade.rdoc +0 -148
- data/generators/integration_spec/integration_spec_generator.rb +0 -10
- data/generators/rspec/CHANGES +0 -1
- data/generators/rspec/rspec_generator.rb +0 -72
- data/generators/rspec/templates/previous_failures.txt +0 -0
- data/generators/rspec/templates/rspec.rake +0 -144
- data/generators/rspec/templates/script/autospec +0 -6
- data/generators/rspec/templates/script/spec +0 -10
- data/generators/rspec_controller/USAGE +0 -33
- data/generators/rspec_controller/rspec_controller_generator.rb +0 -47
- data/generators/rspec_controller/templates/controller_spec.rb +0 -25
- data/generators/rspec_controller/templates/helper_spec.rb +0 -11
- data/generators/rspec_controller/templates/view_spec.rb +0 -12
- data/generators/rspec_default_values.rb +0 -28
- data/generators/rspec_model/USAGE +0 -18
- data/generators/rspec_model/rspec_model_generator.rb +0 -35
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +0 -154
- data/generators/rspec_scaffold/templates/controller_spec.rb +0 -131
- data/generators/rspec_scaffold/templates/helper_spec.rb +0 -11
- data/init.rb +0 -9
- data/lib/autotest/discover.rb +0 -5
- data/lib/autotest/rails_rspec.rb +0 -76
- data/lib/spec/rails.rb +0 -26
- data/lib/spec/rails/example.rb +0 -48
- data/lib/spec/rails/example/assigns_hash_proxy.rb +0 -39
- data/lib/spec/rails/example/controller_example_group.rb +0 -285
- data/lib/spec/rails/example/cookies_proxy.rb +0 -29
- data/lib/spec/rails/example/functional_example_group.rb +0 -106
- data/lib/spec/rails/example/helper_example_group.rb +0 -153
- data/lib/spec/rails/example/integration_example_group.rb +0 -16
- data/lib/spec/rails/example/model_example_group.rb +0 -15
- data/lib/spec/rails/example/render_observer.rb +0 -80
- data/lib/spec/rails/example/routing_example_group.rb +0 -16
- data/lib/spec/rails/example/routing_helpers.rb +0 -66
- data/lib/spec/rails/example/view_example_group.rb +0 -203
- data/lib/spec/rails/extensions.rb +0 -11
- data/lib/spec/rails/extensions/action_controller/rescue.rb +0 -42
- data/lib/spec/rails/extensions/action_controller/test_case.rb +0 -16
- data/lib/spec/rails/extensions/action_controller/test_response.rb +0 -21
- data/lib/spec/rails/extensions/action_view/base.rb +0 -35
- data/lib/spec/rails/extensions/active_record/base.rb +0 -45
- data/lib/spec/rails/extensions/active_support/test_case.rb +0 -7
- data/lib/spec/rails/extensions/spec/matchers/have.rb +0 -23
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +0 -45
- data/lib/spec/rails/interop/testcase.rb +0 -14
- data/lib/spec/rails/matchers.rb +0 -32
- data/lib/spec/rails/matchers/ar_be_valid.rb +0 -27
- data/lib/spec/rails/matchers/assert_select.rb +0 -180
- data/lib/spec/rails/matchers/change.rb +0 -13
- data/lib/spec/rails/matchers/have_text.rb +0 -57
- data/lib/spec/rails/matchers/include_text.rb +0 -54
- data/lib/spec/rails/matchers/redirect_to.rb +0 -126
- data/lib/spec/rails/matchers/render_template.rb +0 -129
- data/lib/spec/rails/matchers/route_to.rb +0 -149
- data/lib/spec/rails/mocks.rb +0 -140
- data/lib/spec/rails/version.rb +0 -16
- data/spec/autotest/mappings_spec.rb +0 -86
- data/spec/rails_suite.rb +0 -7
- data/spec/resources/controllers/action_view_base_spec_controller.rb +0 -2
- data/spec/resources/controllers/application.rb +0 -9
- data/spec/resources/controllers/controller_spec_controller.rb +0 -127
- data/spec/resources/controllers/example.txt +0 -1
- data/spec/resources/controllers/redirect_spec_controller.rb +0 -70
- data/spec/resources/controllers/render_spec_controller.rb +0 -34
- data/spec/resources/controllers/rjs_spec_controller.rb +0 -58
- data/spec/resources/helpers/addition_helper.rb +0 -5
- data/spec/resources/helpers/explicit_helper.rb +0 -46
- data/spec/resources/helpers/more_explicit_helper.rb +0 -5
- data/spec/resources/helpers/plugin_application_helper.rb +0 -6
- data/spec/resources/helpers/view_spec_helper.rb +0 -13
- data/spec/resources/models/animal.rb +0 -4
- data/spec/resources/models/person.rb +0 -18
- data/spec/resources/models/thing.rb +0 -3
- data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
- data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +0 -1
- data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +0 -1
- data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
- data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +0 -1
- data/spec/resources/views/controller_spec/action_with_template.html.erb +0 -1
- data/spec/resources/views/controller_spec/non_existent_action_with_existent_template.html.erb +0 -1
- data/spec/resources/views/layouts/application.html.erb +0 -0
- data/spec/resources/views/layouts/simple.html.erb +0 -0
- data/spec/resources/views/objects/_object.html.erb +0 -1
- data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
- data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
- data/spec/resources/views/render_spec/some_action.html.erb +0 -0
- data/spec/resources/views/render_spec/some_action.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +0 -1
- data/spec/resources/views/rjs_spec/hide_div.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/insert_html.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/replace.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/replace_html.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/visual_effect.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +0 -1
- data/spec/resources/views/tag_spec/no_tags.html.erb +0 -1
- data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +0 -1
- data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +0 -1
- data/spec/resources/views/view_spec/_partial.html.erb +0 -2
- data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
- data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +0 -1
- data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +0 -1
- data/spec/resources/views/view_spec/_spacer.html.erb +0 -1
- data/spec/resources/views/view_spec/accessor.html.erb +0 -6
- data/spec/resources/views/view_spec/block_helper.html.erb +0 -3
- data/spec/resources/views/view_spec/entry_form.html.erb +0 -2
- data/spec/resources/views/view_spec/explicit_helper.html.erb +0 -2
- data/spec/resources/views/view_spec/foo/show.html.erb +0 -1
- data/spec/resources/views/view_spec/implicit_helper.html.erb +0 -2
- data/spec/resources/views/view_spec/multiple_helpers.html.erb +0 -3
- data/spec/resources/views/view_spec/path_params.html.erb +0 -1
- data/spec/resources/views/view_spec/should_not_receive.html.erb +0 -3
- data/spec/resources/views/view_spec/template_with_partial.html.erb +0 -5
- data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +0 -3
- data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +0 -1
- data/spec/resources/views/view_spec/view_helpers.html.erb +0 -1
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +0 -109
- data/spec/spec/rails/example/configuration_spec.rb +0 -67
- data/spec/spec/rails/example/controller_example_group_spec.rb +0 -307
- data/spec/spec/rails/example/controller_isolation_spec.rb +0 -75
- data/spec/spec/rails/example/cookies_proxy_spec.rb +0 -87
- data/spec/spec/rails/example/error_handling_spec.rb +0 -90
- data/spec/spec/rails/example/example_group_factory_spec.rb +0 -112
- data/spec/spec/rails/example/helper_example_group_spec.rb +0 -247
- data/spec/spec/rails/example/model_example_group_spec.rb +0 -32
- data/spec/spec/rails/example/routing_example_group_spec.rb +0 -9
- data/spec/spec/rails/example/shared_routing_example_group_examples.rb +0 -237
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +0 -33
- data/spec/spec/rails/example/view_example_group_spec.rb +0 -346
- data/spec/spec/rails/extensions/action_view_base_spec.rb +0 -79
- data/spec/spec/rails/extensions/active_record_spec.rb +0 -14
- data/spec/spec/rails/interop/testcase_spec.rb +0 -70
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +0 -19
- data/spec/spec/rails/matchers/assert_select_spec.rb +0 -835
- data/spec/spec/rails/matchers/errors_on_spec.rb +0 -37
- data/spec/spec/rails/matchers/have_text_spec.rb +0 -69
- data/spec/spec/rails/matchers/include_text_spec.rb +0 -62
- data/spec/spec/rails/matchers/redirect_to_spec.rb +0 -253
- data/spec/spec/rails/matchers/render_template_spec.rb +0 -208
- data/spec/spec/rails/matchers/should_change_spec.rb +0 -15
- data/spec/spec/rails/mocks/ar_classes.rb +0 -10
- data/spec/spec/rails/mocks/mock_model_spec.rb +0 -112
- data/spec/spec/rails/mocks/stub_model_spec.rb +0 -80
- data/spec/spec/rails/sample_modified_fixture.rb +0 -8
- data/spec/spec/rails/sample_spec.rb +0 -8
- data/spec/spec/rails/spec_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -78
@@ -1,14 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
module Unit
|
3
|
-
class TestCase
|
4
|
-
# Edge rails (r8664) introduces class-wide setup & teardown callbacks for Test::Unit::TestCase.
|
5
|
-
# Make sure these still get run when running TestCases under rspec:
|
6
|
-
prepend_before(:each) do
|
7
|
-
run_callbacks :setup if respond_to?(:run_callbacks)
|
8
|
-
end
|
9
|
-
append_after(:each) do
|
10
|
-
run_callbacks :teardown if respond_to?(:run_callbacks)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/spec/rails/matchers.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Rails
|
3
|
-
# Spec::Rails::Expectations::Matchers provides several expectation matchers
|
4
|
-
# intended to work with Rails components like models and responses. For example:
|
5
|
-
#
|
6
|
-
# response.should redirect_to("some/url") #redirect_to(url) is the matcher.
|
7
|
-
#
|
8
|
-
# In addition to those you see below, the arbitrary predicate feature of RSpec
|
9
|
-
# makes the following available as well:
|
10
|
-
#
|
11
|
-
# response.should be_success #passes if response.success?
|
12
|
-
# response.should be_redirect #passes if response.redirect?
|
13
|
-
#
|
14
|
-
# Note that many of these matchers are part of a wrapper of <tt>assert_select</tt>, so
|
15
|
-
# the documentation comes straight from that with some slight modifications.
|
16
|
-
# <tt>assert_select</tt> is a Test::Unit extension originally contributed to the
|
17
|
-
# Rails community as a plugin by Assaf Arkin and eventually shipped as part of Rails.
|
18
|
-
#
|
19
|
-
# For more info on <tt>assert_select</tt>, see the relevant Rails documentation.
|
20
|
-
module Matchers
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'spec/rails/matchers/ar_be_valid'
|
26
|
-
require 'spec/rails/matchers/assert_select'
|
27
|
-
require 'spec/rails/matchers/change'
|
28
|
-
require 'spec/rails/matchers/have_text'
|
29
|
-
require 'spec/rails/matchers/include_text'
|
30
|
-
require 'spec/rails/matchers/redirect_to'
|
31
|
-
require 'spec/rails/matchers/route_to'
|
32
|
-
require 'spec/rails/matchers/render_template'
|
@@ -1,27 +0,0 @@
|
|
1
|
-
if defined?(ActiveRecord::Base)
|
2
|
-
module Spec
|
3
|
-
module Rails
|
4
|
-
module Matchers
|
5
|
-
# :call-seq:
|
6
|
-
# response.should be_valid
|
7
|
-
# response.should_not be_valid
|
8
|
-
def be_valid
|
9
|
-
::Spec::Matchers::Matcher.new :be_valid do
|
10
|
-
match do |actual|
|
11
|
-
actual.valid?
|
12
|
-
end
|
13
|
-
|
14
|
-
failure_message_for_should do |actual|
|
15
|
-
if actual.respond_to?(:errors) && ActiveRecord::Errors === actual.errors
|
16
|
-
"Expected #{actual.inspect} to be valid, but it was not\nErrors: " + actual.errors.full_messages.join(", ")
|
17
|
-
else
|
18
|
-
"Expected #{actual.inspect} to be valid"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
# This is a wrapper of assert_select for rspec.
|
2
|
-
|
3
|
-
module Spec # :nodoc:
|
4
|
-
module Rails
|
5
|
-
module Matchers
|
6
|
-
|
7
|
-
class AssertSelect #:nodoc:
|
8
|
-
attr_reader :options
|
9
|
-
|
10
|
-
def initialize(selector_assertion, spec_scope, *args, &block)
|
11
|
-
@args, @options = args_and_options(args)
|
12
|
-
@spec_scope = spec_scope
|
13
|
-
@selector_assertion = selector_assertion
|
14
|
-
@block = block
|
15
|
-
end
|
16
|
-
|
17
|
-
def matches?(response_or_text, &block)
|
18
|
-
@block = block if block
|
19
|
-
|
20
|
-
if doc = doc_from(response_or_text)
|
21
|
-
@args.unshift(doc)
|
22
|
-
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
@spec_scope.__send__(@selector_assertion, *@args, &@block)
|
26
|
-
true
|
27
|
-
rescue ::Test::Unit::AssertionFailedError => @error
|
28
|
-
false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def failure_message_for_should; @error.message; end
|
33
|
-
def failure_message_for_should_not; "should not #{description}, but did"; end
|
34
|
-
|
35
|
-
def description
|
36
|
-
{
|
37
|
-
:assert_select => "have tag#{format_args(*@args)}",
|
38
|
-
:assert_select_email => "send email#{format_args(*@args)}",
|
39
|
-
}[@selector_assertion]
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
module TestResponseOrString
|
45
|
-
def test_response?
|
46
|
-
ActionController::TestResponse === self and
|
47
|
-
!self.headers['Content-Type'].blank? and
|
48
|
-
self.headers['Content-Type'].to_sym == :xml
|
49
|
-
end
|
50
|
-
|
51
|
-
def string?
|
52
|
-
String === self
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def doc_from(response_or_text)
|
57
|
-
response_or_text.extend TestResponseOrString
|
58
|
-
if response_or_text.test_response?
|
59
|
-
HTML::Document.new(response_or_text.body, @options[:strict], @options[:xml]).root
|
60
|
-
elsif response_or_text.string?
|
61
|
-
HTML::Document.new(response_or_text, @options[:strict], @options[:xml]).root
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def format_args(*args)
|
66
|
-
args.empty? ? "" : "(#{arg_list(*args)})"
|
67
|
-
end
|
68
|
-
|
69
|
-
def arg_list(*args)
|
70
|
-
args.map do |arg|
|
71
|
-
arg.respond_to?(:description) ? arg.description : arg.inspect
|
72
|
-
end.join(", ")
|
73
|
-
end
|
74
|
-
|
75
|
-
def args_and_options(args)
|
76
|
-
opts = {:xml => false, :strict => false}
|
77
|
-
if args.last.is_a?(::Hash)
|
78
|
-
opts[:strict] = args.last.delete(:strict) unless args.last[:strict].nil?
|
79
|
-
opts[:xml] = args.last.delete(:xml) unless args.last[:xml].nil?
|
80
|
-
args.pop if args.last.empty?
|
81
|
-
end
|
82
|
-
return [args, opts]
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
# :call-seq:
|
88
|
-
# response.should have_tag(*args, &block)
|
89
|
-
# string.should have_tag(*args, &block)
|
90
|
-
#
|
91
|
-
# wrapper for assert_select with additional support for using
|
92
|
-
# css selectors to set expectation on Strings. Use this in
|
93
|
-
# helper specs, for example, to set expectations on the results
|
94
|
-
# of helper methods. Also allow specification of how the
|
95
|
-
# response is parsed using the options :xml and :strict options.
|
96
|
-
# By default, these options are set to false.
|
97
|
-
#
|
98
|
-
# == Examples
|
99
|
-
#
|
100
|
-
# # in a controller spec
|
101
|
-
# response.should have_tag("div", "some text")
|
102
|
-
#
|
103
|
-
# # to force xml and/or strict parsing of the response
|
104
|
-
# response.should have_tag("div", "some text", :xml => true)
|
105
|
-
# response.should have_tag("div", "some text", :strict => true)
|
106
|
-
# response.should have_tag("div", "some text", :xml => true, :strict => false)
|
107
|
-
#
|
108
|
-
# # in a helper spec (person_address_tag is a method in the helper)
|
109
|
-
# person_address_tag.should have_tag("input#person_address")
|
110
|
-
#
|
111
|
-
# see documentation for assert_select at http://api.rubyonrails.org/
|
112
|
-
def have_tag(*args, &block)
|
113
|
-
@__current_scope_for_assert_select = AssertSelect.new(:assert_select, self, *args, &block)
|
114
|
-
end
|
115
|
-
|
116
|
-
# wrapper for a nested assert_select
|
117
|
-
#
|
118
|
-
# response.should have_tag("div#form") do
|
119
|
-
# with_tag("input#person_name[name=?]", "person[name]")
|
120
|
-
# end
|
121
|
-
#
|
122
|
-
# see documentation for assert_select at http://api.rubyonrails.org/
|
123
|
-
def with_tag(*args, &block)
|
124
|
-
args = prepare_args(args, @__current_scope_for_assert_select)
|
125
|
-
@__current_scope_for_assert_select.should have_tag(*args, &block)
|
126
|
-
end
|
127
|
-
|
128
|
-
# wrapper for a nested assert_select with false
|
129
|
-
#
|
130
|
-
# response.should have_tag("div#1") do
|
131
|
-
# without_tag("span", "some text that shouldn't be there")
|
132
|
-
# end
|
133
|
-
#
|
134
|
-
# see documentation for assert_select at http://api.rubyonrails.org/
|
135
|
-
def without_tag(*args, &block)
|
136
|
-
args = prepare_args(args, @__current_scope_for_assert_select)
|
137
|
-
@__current_scope_for_assert_select.should_not have_tag(*args, &block)
|
138
|
-
end
|
139
|
-
|
140
|
-
# :call-seq:
|
141
|
-
# response.should have_rjs(*args, &block)
|
142
|
-
#
|
143
|
-
# wrapper for assert_select_rjs
|
144
|
-
#
|
145
|
-
# see documentation for assert_select_rjs at http://api.rubyonrails.org/
|
146
|
-
def have_rjs(*args, &block)
|
147
|
-
AssertSelect.new(:assert_select_rjs, self, *args, &block)
|
148
|
-
end
|
149
|
-
|
150
|
-
# :call-seq:
|
151
|
-
# response.should send_email(*args, &block)
|
152
|
-
#
|
153
|
-
# wrapper for assert_select_email
|
154
|
-
#
|
155
|
-
# see documentation for assert_select_email at http://api.rubyonrails.org/
|
156
|
-
def send_email(*args, &block)
|
157
|
-
AssertSelect.new(:assert_select_email, self, *args, &block)
|
158
|
-
end
|
159
|
-
|
160
|
-
# wrapper for assert_select_encoded
|
161
|
-
#
|
162
|
-
# see documentation for assert_select_encoded at http://api.rubyonrails.org/
|
163
|
-
def with_encoded(*args, &block)
|
164
|
-
should AssertSelect.new(:assert_select_encoded, self, *args, &block)
|
165
|
-
end
|
166
|
-
|
167
|
-
private
|
168
|
-
|
169
|
-
def prepare_args(args, current_scope = nil)
|
170
|
-
return args if current_scope.nil?
|
171
|
-
defaults = current_scope.options || {:strict => false, :xml => false}
|
172
|
-
args << {} unless args.last.is_a?(::Hash)
|
173
|
-
args.last[:strict] = defaults[:strict] if args.last[:strict].nil?
|
174
|
-
args.last[:xml] = defaults[:xml] if args.last[:xml].nil?
|
175
|
-
args
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
if defined?(ActiveRecord::Base)
|
2
|
-
module Spec
|
3
|
-
module Matchers
|
4
|
-
class Change
|
5
|
-
def evaluate_value_proc_with_ensured_evaluation_of_proxy
|
6
|
-
value = evaluate_value_proc_without_ensured_evaluation_of_proxy
|
7
|
-
ActiveRecord::Associations::AssociationProxy === value ? value.dup : value
|
8
|
-
end
|
9
|
-
alias_method_chain :evaluate_value_proc, :ensured_evaluation_of_proxy
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Rails
|
3
|
-
module Matchers
|
4
|
-
|
5
|
-
class HaveText #:nodoc:
|
6
|
-
|
7
|
-
def initialize(expected)
|
8
|
-
@expected = expected
|
9
|
-
end
|
10
|
-
|
11
|
-
def matches?(response_or_text)
|
12
|
-
@actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
|
13
|
-
return actual =~ expected if Regexp === expected
|
14
|
-
return actual == expected unless Regexp === expected
|
15
|
-
end
|
16
|
-
|
17
|
-
def failure_message_for_should
|
18
|
-
"expected #{expected.inspect}, got #{actual.inspect}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def failure_message_for_should_not
|
22
|
-
"expected not to have text #{expected.inspect}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def description
|
26
|
-
"have text #{expected.inspect}"
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
attr_reader :expected
|
31
|
-
attr_reader :actual
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
# :call-seq:
|
36
|
-
# response.should have_text(expected)
|
37
|
-
# response.should_not have_text(expected)
|
38
|
-
#
|
39
|
-
# Accepts a String or a Regexp, matching a String using ==
|
40
|
-
# and a Regexp using =~.
|
41
|
-
#
|
42
|
-
# If response_or_text has a #body, then that is used as to match against
|
43
|
-
# else it uses response_or_text
|
44
|
-
#
|
45
|
-
# Use this instead of <tt>response.should have_tag()</tt>
|
46
|
-
# when you want to match the whole string or whole body
|
47
|
-
#
|
48
|
-
# == Examples
|
49
|
-
#
|
50
|
-
# response.should have_text("This is the expected text")
|
51
|
-
def have_text(text)
|
52
|
-
HaveText.new(text)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Rails
|
3
|
-
module Matchers
|
4
|
-
|
5
|
-
class IncludeText #:nodoc:
|
6
|
-
|
7
|
-
def initialize(expected)
|
8
|
-
@expected = expected
|
9
|
-
end
|
10
|
-
|
11
|
-
def matches?(response_or_text)
|
12
|
-
@actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
|
13
|
-
return actual.include?(expected)
|
14
|
-
end
|
15
|
-
|
16
|
-
def failure_message_for_should
|
17
|
-
"expected to find #{expected.inspect} in #{actual.inspect}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def failure_message_for_should_not
|
21
|
-
"expected not to include text #{expected.inspect}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def description
|
25
|
-
"include text #{expected.inspect}"
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
attr_reader :expected
|
30
|
-
attr_reader :actual
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
# :call-seq:
|
36
|
-
# response.should include_text(expected)
|
37
|
-
# response.should_not include_text(expected)
|
38
|
-
#
|
39
|
-
# Accepts a String, matching using include?
|
40
|
-
#
|
41
|
-
# Use this instead of <tt>response.should have_text()</tt>
|
42
|
-
# when you either don't know or don't care where on the page
|
43
|
-
# this text appears.
|
44
|
-
#
|
45
|
-
# == Examples
|
46
|
-
#
|
47
|
-
# response.should include_text("This text will be in the actual string")
|
48
|
-
def include_text(text)
|
49
|
-
IncludeText.new(text)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Rails
|
3
|
-
module Matchers
|
4
|
-
|
5
|
-
class RedirectTo #:nodoc:
|
6
|
-
|
7
|
-
include ActionController::StatusCodes
|
8
|
-
|
9
|
-
def initialize(request, expected)
|
10
|
-
@expected = expected
|
11
|
-
@request = request
|
12
|
-
end
|
13
|
-
|
14
|
-
def matches?(response_or_controller)
|
15
|
-
response = response_or_controller.respond_to?(:response) ?
|
16
|
-
response_or_controller.response :
|
17
|
-
response_or_controller
|
18
|
-
|
19
|
-
@redirected = response.redirect?
|
20
|
-
@actual = response.redirect_url
|
21
|
-
return false unless @redirected
|
22
|
-
|
23
|
-
if @expected_status
|
24
|
-
@actual_status = interpret_status(response.code.to_i)
|
25
|
-
@status_matched = @expected_status == @actual_status
|
26
|
-
else
|
27
|
-
@status_matched = true
|
28
|
-
end
|
29
|
-
|
30
|
-
if @expected.instance_of? Hash
|
31
|
-
return false unless @actual =~ %r{^\w+://#{@request.host}}
|
32
|
-
return false unless actual_redirect_to_valid_route
|
33
|
-
return actual_hash == expected_hash && @status_matched
|
34
|
-
else
|
35
|
-
return @actual == expected_url && @status_matched
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def actual_hash
|
40
|
-
hash_from_url @actual
|
41
|
-
end
|
42
|
-
|
43
|
-
def expected_hash
|
44
|
-
hash_from_url expected_url
|
45
|
-
end
|
46
|
-
|
47
|
-
def actual_redirect_to_valid_route
|
48
|
-
actual_hash
|
49
|
-
end
|
50
|
-
|
51
|
-
def hash_from_url(url)
|
52
|
-
query_hash(url).merge(path_hash(url)).with_indifferent_access
|
53
|
-
end
|
54
|
-
|
55
|
-
def path_hash(url)
|
56
|
-
path = url.sub(%r{^\w+://#{@request.host}(?::\d+)?}, "").split("?", 2)[0]
|
57
|
-
ActionController::Routing::Routes.recognize_path path, { :method => :get }
|
58
|
-
end
|
59
|
-
|
60
|
-
def query_hash(url)
|
61
|
-
query = url.split("?", 2)[1] || ""
|
62
|
-
Rack::Utils.parse_query(query)
|
63
|
-
end
|
64
|
-
|
65
|
-
def with(options)
|
66
|
-
@expected_status = interpret_status(options[:status])
|
67
|
-
self
|
68
|
-
end
|
69
|
-
|
70
|
-
def expected_url
|
71
|
-
case @expected
|
72
|
-
when Hash
|
73
|
-
return ActionController::UrlRewriter.new(@request, {}).rewrite(@expected)
|
74
|
-
when :back
|
75
|
-
return @request.env['HTTP_REFERER']
|
76
|
-
when %r{^\w+://.*}
|
77
|
-
return @expected
|
78
|
-
else
|
79
|
-
return "http://#{@request.host}" + (@expected.split('')[0] == '/' ? '' : '/') + @expected
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def failure_message_for_should
|
84
|
-
if @redirected
|
85
|
-
if @status_matched
|
86
|
-
return %Q{expected redirect to #{@expected.inspect}, got redirect to #{@actual.inspect}}
|
87
|
-
else
|
88
|
-
return %Q{expected redirect to #{@expected.inspect} with status #{@expected_status}, got #{@actual_status}}
|
89
|
-
end
|
90
|
-
else
|
91
|
-
return %Q{expected redirect to #{@expected.inspect}, got no redirect}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def failure_message_for_should_not
|
96
|
-
return %Q{expected not to be redirected to #{@expected.inspect}, but was} if @redirected
|
97
|
-
end
|
98
|
-
|
99
|
-
def description
|
100
|
-
"redirect to #{@expected.inspect}"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# :call-seq:
|
105
|
-
# response.should redirect_to(url)
|
106
|
-
# response.should redirect_to(:action => action_name)
|
107
|
-
# response.should redirect_to(:controller => controller_name, :action => action_name)
|
108
|
-
# response.should_not redirect_to(url)
|
109
|
-
# response.should_not redirect_to(:action => action_name)
|
110
|
-
# response.should_not redirect_to(:controller => controller_name, :action => action_name)
|
111
|
-
#
|
112
|
-
# Passes if the response is a redirect to the url, action or controller/action.
|
113
|
-
# Useful in controller specs (integration or isolation mode).
|
114
|
-
#
|
115
|
-
# == Examples
|
116
|
-
#
|
117
|
-
# response.should redirect_to("path/to/action")
|
118
|
-
# response.should redirect_to("http://test.host/path/to/action")
|
119
|
-
# response.should redirect_to(:action => 'list')
|
120
|
-
def redirect_to(opts)
|
121
|
-
RedirectTo.new(request, opts)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
end
|