cavalle-rspec-rails 1.2.2.0.1
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/.document +7 -0
- data/History.rdoc +207 -0
- data/License.txt +33 -0
- data/Manifest.txt +167 -0
- data/README.rdoc +45 -0
- data/Rakefile +79 -0
- data/TODO.txt +1 -0
- data/Upgrade.rdoc +103 -0
- data/features/step_definitions/people.rb +6 -0
- data/features/support/env.rb +13 -0
- data/features/transactions/transactions_should_rollback.feature +16 -0
- data/generators/rspec/CHANGES +1 -0
- data/generators/rspec/rspec_generator.rb +54 -0
- data/generators/rspec/templates/previous_failures.txt +0 -0
- data/generators/rspec/templates/rcov.opts +2 -0
- data/generators/rspec/templates/rspec.rake +165 -0
- data/generators/rspec/templates/script/autospec +6 -0
- data/generators/rspec/templates/script/spec +10 -0
- data/generators/rspec/templates/script/spec_server +9 -0
- data/generators/rspec/templates/spec.opts +4 -0
- data/generators/rspec/templates/spec_helper.rb +47 -0
- data/generators/rspec_controller/USAGE +33 -0
- data/generators/rspec_controller/rspec_controller_generator.rb +45 -0
- data/generators/rspec_controller/templates/controller_spec.rb +25 -0
- data/generators/rspec_controller/templates/helper_spec.rb +11 -0
- data/generators/rspec_controller/templates/view_spec.rb +12 -0
- data/generators/rspec_default_values.rb +19 -0
- data/generators/rspec_model/USAGE +18 -0
- data/generators/rspec_model/rspec_model_generator.rb +35 -0
- data/generators/rspec_model/templates/model_spec.rb +15 -0
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +150 -0
- data/generators/rspec_scaffold/templates/controller_spec.rb +171 -0
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +27 -0
- data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +28 -0
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +27 -0
- data/generators/rspec_scaffold/templates/routing_spec.rb +63 -0
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
- data/init.rb +9 -0
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rails_rspec.rb +76 -0
- data/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
- data/lib/spec/rails/example/controller_example_group.rb +247 -0
- data/lib/spec/rails/example/cookies_proxy.rb +29 -0
- data/lib/spec/rails/example/functional_example_group.rb +84 -0
- data/lib/spec/rails/example/helper_example_group.rb +153 -0
- data/lib/spec/rails/example/model_example_group.rb +14 -0
- data/lib/spec/rails/example/render_observer.rb +67 -0
- data/lib/spec/rails/example/routing_example_group.rb +13 -0
- data/lib/spec/rails/example/routing_helpers.rb +70 -0
- data/lib/spec/rails/example/view_example_group.rb +186 -0
- data/lib/spec/rails/example.rb +47 -0
- data/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
- data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
- data/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
- data/lib/spec/rails/extensions/action_view/base.rb +33 -0
- data/lib/spec/rails/extensions/active_record/base.rb +45 -0
- data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
- data/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +44 -0
- data/lib/spec/rails/extensions.rb +11 -0
- data/lib/spec/rails/interop/testcase.rb +14 -0
- data/lib/spec/rails/matchers/ar_be_valid.rb +44 -0
- data/lib/spec/rails/matchers/assert_select.rb +146 -0
- data/lib/spec/rails/matchers/change.rb +11 -0
- data/lib/spec/rails/matchers/have_text.rb +57 -0
- data/lib/spec/rails/matchers/include_text.rb +54 -0
- data/lib/spec/rails/matchers/redirect_to.rb +126 -0
- data/lib/spec/rails/matchers/render_template.rb +114 -0
- data/lib/spec/rails/matchers.rb +32 -0
- data/lib/spec/rails/mocks.rb +135 -0
- data/lib/spec/rails/spec_server.rb +127 -0
- data/lib/spec/rails/story_adapter.rb +79 -0
- data/lib/spec/rails/version.rb +15 -0
- data/lib/spec/rails.rb +28 -0
- data/rspec-rails.gemspec +57 -0
- data/spec/autotest/mappings_spec.rb +86 -0
- data/spec/rails_suite.rb +7 -0
- data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
- data/spec/resources/controllers/application.rb +9 -0
- data/spec/resources/controllers/controller_spec_controller.rb +120 -0
- data/spec/resources/controllers/example.txt +1 -0
- data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
- data/spec/resources/controllers/render_spec_controller.rb +30 -0
- data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
- data/spec/resources/helpers/addition_helper.rb +5 -0
- data/spec/resources/helpers/explicit_helper.rb +46 -0
- data/spec/resources/helpers/more_explicit_helper.rb +5 -0
- data/spec/resources/helpers/plugin_application_helper.rb +6 -0
- data/spec/resources/helpers/view_spec_helper.rb +13 -0
- data/spec/resources/models/animal.rb +4 -0
- data/spec/resources/models/person.rb +18 -0
- data/spec/resources/models/thing.rb +3 -0
- 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 +1 -0
- data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +1 -0
- 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 +1 -0
- data/spec/resources/views/controller_spec/action_with_template.html.erb +1 -0
- 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 +1 -0
- 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 +1 -0
- data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +1 -0
- data/spec/resources/views/rjs_spec/hide_div.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/insert_html.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/replace.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/replace_html.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/visual_effect.js.rjs +1 -0
- data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +1 -0
- data/spec/resources/views/tag_spec/no_tags.html.erb +1 -0
- data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +1 -0
- data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +1 -0
- data/spec/resources/views/view_spec/_partial.html.erb +2 -0
- 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 +1 -0
- data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +1 -0
- data/spec/resources/views/view_spec/_spacer.html.erb +1 -0
- data/spec/resources/views/view_spec/accessor.html.erb +5 -0
- data/spec/resources/views/view_spec/block_helper.html.erb +3 -0
- data/spec/resources/views/view_spec/entry_form.html.erb +2 -0
- data/spec/resources/views/view_spec/explicit_helper.html.erb +2 -0
- data/spec/resources/views/view_spec/foo/show.html.erb +1 -0
- data/spec/resources/views/view_spec/implicit_helper.html.erb +2 -0
- data/spec/resources/views/view_spec/multiple_helpers.html.erb +3 -0
- data/spec/resources/views/view_spec/path_params.html.erb +1 -0
- data/spec/resources/views/view_spec/should_not_receive.html.erb +3 -0
- data/spec/resources/views/view_spec/template_with_partial.html.erb +5 -0
- data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +3 -0
- data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +1 -0
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
- data/spec/spec/rails/example/configuration_spec.rb +65 -0
- data/spec/spec/rails/example/controller_example_group_spec.rb +299 -0
- data/spec/spec/rails/example/controller_isolation_spec.rb +56 -0
- data/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
- data/spec/spec/rails/example/error_handling_spec.rb +90 -0
- data/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
- data/spec/spec/rails/example/helper_example_group_spec.rb +233 -0
- data/spec/spec/rails/example/model_example_group_spec.rb +20 -0
- data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
- data/spec/spec/rails/example/shared_routing_example_group_examples.rb +44 -0
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
- data/spec/spec/rails/example/view_example_group_spec.rb +335 -0
- data/spec/spec/rails/extensions/action_view_base_spec.rb +48 -0
- data/spec/spec/rails/extensions/active_record_spec.rb +14 -0
- data/spec/spec/rails/interop/testcase_spec.rb +70 -0
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +45 -0
- data/spec/spec/rails/matchers/assert_select_spec.rb +809 -0
- data/spec/spec/rails/matchers/errors_on_spec.rb +25 -0
- data/spec/spec/rails/matchers/have_text_spec.rb +70 -0
- data/spec/spec/rails/matchers/include_text_spec.rb +62 -0
- data/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
- data/spec/spec/rails/matchers/render_template_spec.rb +191 -0
- data/spec/spec/rails/matchers/should_change_spec.rb +15 -0
- data/spec/spec/rails/mocks/ar_classes.rb +10 -0
- data/spec/spec/rails/mocks/mock_model_spec.rb +106 -0
- data/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
- data/spec/spec/rails/sample_modified_fixture.rb +8 -0
- data/spec/spec/rails/sample_spec.rb +8 -0
- data/spec/spec/rails/spec_server_spec.rb +107 -0
- data/spec/spec/rails/spec_spec.rb +11 -0
- data/spec/spec_helper.rb +79 -0
- metadata +277 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
module Spec
|
2
|
+
module Rails
|
3
|
+
module Example
|
4
|
+
class ViewExampleGroupController < ApplicationController #:nodoc:
|
5
|
+
include Spec::Rails::Example::RenderObserver
|
6
|
+
attr_reader :template
|
7
|
+
|
8
|
+
def add_helper_for(template_path)
|
9
|
+
add_helper(template_path.split('/')[0])
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_helper(name)
|
13
|
+
begin
|
14
|
+
helper_module = "#{name}_helper".camelize.constantize
|
15
|
+
rescue
|
16
|
+
return
|
17
|
+
end
|
18
|
+
(class << template; self; end).class_eval do
|
19
|
+
include helper_module
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def forget_variables_added_to_assigns
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# View Examples live in $RAILS_ROOT/spec/views/.
|
28
|
+
#
|
29
|
+
# View Specs use Spec::Rails::Example::ViewExampleGroup,
|
30
|
+
# which provides access to views without invoking any of your controllers.
|
31
|
+
# See Spec::Rails::Expectations::Matchers for information about specific
|
32
|
+
# expectations that you can set on views.
|
33
|
+
#
|
34
|
+
# == Example
|
35
|
+
#
|
36
|
+
# describe "login/login" do
|
37
|
+
# before do
|
38
|
+
# render 'login/login'
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# it "should display login form" do
|
42
|
+
# response.should have_tag("form[action=/login]") do
|
43
|
+
# with_tag("input[type=text][name=email]")
|
44
|
+
# with_tag("input[type=password][name=password]")
|
45
|
+
# with_tag("input[type=submit][value=Login]")
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
class ViewExampleGroup < FunctionalExampleGroup
|
50
|
+
tests ViewExampleGroupController
|
51
|
+
class << self
|
52
|
+
def inherited(klass) # :nodoc:
|
53
|
+
klass.subject { template }
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
before {ensure_that_flash_and_session_work_properly}
|
59
|
+
after {ensure_that_base_view_path_is_not_set_across_example_groups}
|
60
|
+
|
61
|
+
def ensure_that_flash_and_session_work_properly #:nodoc:
|
62
|
+
@controller.class.__send__ :public, :flash
|
63
|
+
@controller.__send__ :initialize_template_class, @response
|
64
|
+
@controller.__send__ :assign_shortcuts, @request, @response
|
65
|
+
@controller.__send__ :initialize_current_url
|
66
|
+
@session = @controller.session
|
67
|
+
end
|
68
|
+
|
69
|
+
def ensure_that_base_view_path_is_not_set_across_example_groups #:nodoc:
|
70
|
+
ActionView::Base.base_view_path = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_base_view_path(options) #:nodoc:
|
74
|
+
ActionView::Base.base_view_path = base_view_path(options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def base_view_path(options) #:nodoc:
|
78
|
+
"/#{derived_controller_name(options)}/"
|
79
|
+
end
|
80
|
+
|
81
|
+
def derived_controller_name(options) #:nodoc:
|
82
|
+
parts = subject_of_render(options).split('/').reject { |part| part.empty? }
|
83
|
+
"#{parts[0..-2].join('/')}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def derived_action_name(options) #:nodoc:
|
87
|
+
parts = subject_of_render(options).split('/').reject { |part| part.empty? }
|
88
|
+
"#{parts.last}".split('.').first
|
89
|
+
end
|
90
|
+
|
91
|
+
def subject_of_render(options) #:nodoc:
|
92
|
+
[:template, :partial, :file].each do |render_type|
|
93
|
+
if options.has_key?(render_type)
|
94
|
+
return options[render_type]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return ""
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_helpers(options) #:nodoc:
|
101
|
+
@controller.add_helper("application")
|
102
|
+
@controller.add_helper(derived_controller_name(options))
|
103
|
+
@controller.add_helper(options[:helper]) if options[:helper]
|
104
|
+
options[:helpers].each { |helper| @controller.add_helper(helper) } if options[:helpers]
|
105
|
+
end
|
106
|
+
|
107
|
+
# Renders a template for a View Spec, which then provides access to the result
|
108
|
+
# through the +response+. Also supports render with :inline, which you can
|
109
|
+
# use to spec custom form builders, helpers, etc, in the context of a view.
|
110
|
+
#
|
111
|
+
# == Examples
|
112
|
+
#
|
113
|
+
# render('/people/list')
|
114
|
+
# render('/people/list', :helper => MyHelper)
|
115
|
+
# render('/people/list', :helpers => [MyHelper, MyOtherHelper])
|
116
|
+
# render(:partial => '/people/_address')
|
117
|
+
# render(:inline => "<% custom_helper 'argument', 'another argument' %>")
|
118
|
+
#
|
119
|
+
# See Spec::Rails::Example::ViewExampleGroup for more information.
|
120
|
+
def render(*args)
|
121
|
+
options = Hash === args.last ? args.pop : {}
|
122
|
+
|
123
|
+
if args.empty?
|
124
|
+
unless [:partial, :inline, :file, :template, :xml, :json, :update].any? {|k| options.has_key? k}
|
125
|
+
args << self.class.description_parts.first
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
options[:template] = args.first.to_s.sub(/^\//,'') unless args.empty?
|
130
|
+
|
131
|
+
set_base_view_path(options)
|
132
|
+
add_helpers(options)
|
133
|
+
|
134
|
+
assigns[:action_name] = @action_name
|
135
|
+
|
136
|
+
@request.path_parameters = @request.path_parameters.merge(
|
137
|
+
:controller => derived_controller_name(options),
|
138
|
+
:action => derived_action_name(options)
|
139
|
+
).merge(options[:path_parameters] || {})
|
140
|
+
|
141
|
+
defaults = { :layout => false }
|
142
|
+
options = defaults.merge options
|
143
|
+
|
144
|
+
@controller.__send__(:params).reverse_merge! @request.parameters
|
145
|
+
|
146
|
+
@controller.class.instance_eval %{
|
147
|
+
def controller_path
|
148
|
+
"#{derived_controller_name(options)}"
|
149
|
+
end
|
150
|
+
|
151
|
+
def controller_name
|
152
|
+
"#{derived_controller_name(options).split('/').last}"
|
153
|
+
end
|
154
|
+
}
|
155
|
+
|
156
|
+
@controller.__send__ :forget_variables_added_to_assigns
|
157
|
+
@controller.__send__ :render, options
|
158
|
+
@controller.__send__ :process_cleanup
|
159
|
+
end
|
160
|
+
|
161
|
+
# This provides the template. Use this to set mock
|
162
|
+
# expectations for dealing with partials
|
163
|
+
#
|
164
|
+
# == Example
|
165
|
+
#
|
166
|
+
# describe "/person/new" do
|
167
|
+
# it "should use the form partial" do
|
168
|
+
# template.should_receive(:render).with(:partial => 'form')
|
169
|
+
# render "/person/new"
|
170
|
+
# end
|
171
|
+
# end
|
172
|
+
def template
|
173
|
+
@controller.template
|
174
|
+
end
|
175
|
+
|
176
|
+
Spec::Example::ExampleGroupFactory.register(:view, self)
|
177
|
+
|
178
|
+
protected
|
179
|
+
def _assigns_hash_proxy
|
180
|
+
@_assigns_hash_proxy ||= AssignsHashProxy.new(self) {@response.template}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'spec/rails/example/routing_helpers'
|
4
|
+
require 'spec/rails/example/assigns_hash_proxy'
|
5
|
+
require "spec/rails/example/render_observer"
|
6
|
+
require "spec/rails/example/model_example_group"
|
7
|
+
require "spec/rails/example/functional_example_group"
|
8
|
+
require "spec/rails/example/controller_example_group"
|
9
|
+
require "spec/rails/example/helper_example_group"
|
10
|
+
require "spec/rails/example/view_example_group"
|
11
|
+
require "spec/rails/example/routing_example_group"
|
12
|
+
require "spec/rails/example/cookies_proxy"
|
13
|
+
|
14
|
+
module Spec
|
15
|
+
module Rails
|
16
|
+
# Spec::Rails::Example extends Spec::Example (RSpec's core Example module) to provide
|
17
|
+
# Rails-specific contexts for describing Rails Models, Views, Controllers and Helpers.
|
18
|
+
#
|
19
|
+
# == Model Examples
|
20
|
+
#
|
21
|
+
# These are the equivalent of unit tests in Rails' built in testing. Ironically (for the traditional TDD'er) these are the only specs that we feel should actually interact with the database.
|
22
|
+
#
|
23
|
+
# See Spec::Rails::Example::ModelExampleGroup
|
24
|
+
#
|
25
|
+
# == Controller Examples
|
26
|
+
#
|
27
|
+
# These align somewhat with functional tests in rails, except that they do not actually render views (though you can force rendering of views if you prefer). Instead of setting expectations about what goes on a page, you set expectations about what templates get rendered.
|
28
|
+
#
|
29
|
+
# See Spec::Rails::Example::ControllerExampleGroup
|
30
|
+
#
|
31
|
+
# == View Examples
|
32
|
+
#
|
33
|
+
# This is the other half of Rails functional testing. View specs allow you to set up assigns and render
|
34
|
+
# a template. By assigning mock model data, you can specify view behaviour with no dependency on a database
|
35
|
+
# or your real models.
|
36
|
+
#
|
37
|
+
# See Spec::Rails::Example::ViewExampleGroup
|
38
|
+
#
|
39
|
+
# == Helper Examples
|
40
|
+
#
|
41
|
+
# These let you specify directly methods that live in your helpers.
|
42
|
+
#
|
43
|
+
# See Spec::Rails::Example::HelperExampleGroup
|
44
|
+
module Example
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActionController
|
2
|
+
module Rescue
|
3
|
+
def use_rails_error_handling!
|
4
|
+
Kernel.warn <<-WARNING
|
5
|
+
DEPRECATION NOTICE: controller.use_rails_error_handling! is
|
6
|
+
deprecated and will be removed from a future version of
|
7
|
+
rspec-rails.
|
8
|
+
|
9
|
+
Use rescue_action_in_public!, which is defined directly in
|
10
|
+
rails' testing framework, instead.
|
11
|
+
WARNING
|
12
|
+
if Rails::VERSION::STRING =~ /^2\.0/
|
13
|
+
@use_rails_error_handling = true
|
14
|
+
else
|
15
|
+
# anything but 0.0.0.0 - borrowed from rails own rescue_action_in_public!
|
16
|
+
request.remote_addr = '208.77.188.166'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def use_rails_error_handling?
|
21
|
+
@use_rails_error_handling ||= false
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
if Rails::VERSION::STRING =~ /^2\.0/
|
27
|
+
def rescue_action_in_public?
|
28
|
+
request.respond_to?(:rescue_action_in_public?) and request.rescue_action_in_public?
|
29
|
+
end
|
30
|
+
|
31
|
+
def rescue_action_with_handler_with_fast_errors(exception)
|
32
|
+
if (use_rails_error_handling? || rescue_action_in_public?) & !handler_for_rescue(exception)
|
33
|
+
rescue_action_in_public(exception)
|
34
|
+
else
|
35
|
+
rescue_action_with_handler_without_fast_errors(exception)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
alias_method_chain :rescue_action_with_handler, :fast_errors
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActionController
|
2
|
+
class TestCase
|
3
|
+
include ::Spec::Rails::Example::RoutingHelpers
|
4
|
+
|
5
|
+
if Rails::VERSION::STRING =~ /2\.0/
|
6
|
+
# Introduced in Rails 2.1, but we need it for 2.0
|
7
|
+
def rescue_action_in_public!
|
8
|
+
# See rescue.rb in this same directory
|
9
|
+
def request.rescue_action_in_public?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActionController #:nodoc:
|
2
|
+
class TestResponse #:nodoc:
|
3
|
+
attr_writer :controller_path
|
4
|
+
|
5
|
+
def capture(name)
|
6
|
+
template.instance_variable_get "@content_for_#{name.to_s}"
|
7
|
+
end
|
8
|
+
|
9
|
+
if ::Rails::VERSION::STRING < "2.3"
|
10
|
+
def [](name)
|
11
|
+
Kernel.warn <<-WARNING
|
12
|
+
DEPRECATION NOTICE: [](name) as an alias for capture(name) (TestResponse
|
13
|
+
extension in rspec-rails) is deprecated and will not be defined by rspec-rails
|
14
|
+
when working with rails >= 2.3.0. It will also be removed entirely from
|
15
|
+
a future version of rspec-rails.
|
16
|
+
WARNING
|
17
|
+
capture(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActionView #:nodoc:
|
2
|
+
class Base #:nodoc:
|
3
|
+
include Spec::Rails::Example::RenderObserver
|
4
|
+
cattr_accessor :base_view_path
|
5
|
+
|
6
|
+
def render_partial_with_base_view_path_handling(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc:
|
7
|
+
if partial_path.is_a?(String)
|
8
|
+
unless partial_path.include?("/")
|
9
|
+
unless self.class.base_view_path.nil?
|
10
|
+
partial_path = "#{self.class.base_view_path}/#{partial_path}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
begin
|
15
|
+
render_partial_without_base_view_path_handling(partial_path, local_assigns, deprecated_local_assigns)
|
16
|
+
rescue ArgumentError # edge rails > 2.1 changed render_partial to accept only one arg
|
17
|
+
render_partial_without_base_view_path_handling(partial_path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_method_chain :render_partial, :base_view_path_handling
|
21
|
+
|
22
|
+
def render_with_mock_proxy(options = {}, old_local_assigns = {}, &block)
|
23
|
+
if render_proxy.__send__(:__mock_proxy).__send__(:find_matching_expectation, :render, options)
|
24
|
+
render_proxy.render(options)
|
25
|
+
else
|
26
|
+
unless render_proxy.__send__(:__mock_proxy).__send__(:find_matching_method_stub, :render, options)
|
27
|
+
render_without_mock_proxy(options, old_local_assigns, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias_method_chain :render, :mock_proxy
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
if defined?(ActiveRecord::Base)
|
2
|
+
module Spec
|
3
|
+
module Rails
|
4
|
+
module Extensions
|
5
|
+
module ActiveRecord
|
6
|
+
module ClassMethods
|
7
|
+
# :call-seq:
|
8
|
+
# ModelClass.should have(:no).records
|
9
|
+
# ModelClass.should have(1).record
|
10
|
+
# ModelClass.should have(n).records
|
11
|
+
#
|
12
|
+
# Extension to enhance <tt>should have</tt> on AR Model classes
|
13
|
+
def records
|
14
|
+
find(:all)
|
15
|
+
end
|
16
|
+
alias :record :records
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
# :call-seq:
|
21
|
+
# model.should have(:no).errors_on(:attribute)
|
22
|
+
# model.should have(1).error_on(:attribute)
|
23
|
+
# model.should have(n).errors_on(:attribute)
|
24
|
+
#
|
25
|
+
# Extension to enhance <tt>should have</tt> on AR Model instances.
|
26
|
+
# Calls model.valid? in order to prepare the object's errors
|
27
|
+
# object.
|
28
|
+
def errors_on(attribute)
|
29
|
+
self.valid?
|
30
|
+
[self.errors.on(attribute)].flatten.compact
|
31
|
+
end
|
32
|
+
alias :error_on :errors_on
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module ActiveRecord #:nodoc:
|
40
|
+
class Base
|
41
|
+
extend Spec::Rails::Extensions::ActiveRecord::ClassMethods
|
42
|
+
include Spec::Rails::Extensions::ActiveRecord::InstanceMethods
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec/matchers/have'
|
2
|
+
|
3
|
+
module Spec #:nodoc:
|
4
|
+
module Matchers #:nodoc:
|
5
|
+
class Have #:nodoc:
|
6
|
+
|
7
|
+
def failure_message_for_should_with_errors_on_extensions
|
8
|
+
return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
|
9
|
+
return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
|
10
|
+
return failure_message_without_errors_on_extensions
|
11
|
+
end
|
12
|
+
alias_method_chain :failure_message_for_should, :errors_on_extensions
|
13
|
+
|
14
|
+
def description_with_errors_on_extensions
|
15
|
+
return "should have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
|
16
|
+
return "should have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
|
17
|
+
return description_without_errors_on_extensions
|
18
|
+
end
|
19
|
+
alias_method_chain :description, :errors_on_extensions
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec/runner/configuration'
|
2
|
+
require 'test_help'
|
3
|
+
|
4
|
+
if defined?(ActiveRecord::Base)
|
5
|
+
module Spec
|
6
|
+
module Runner
|
7
|
+
class Configuration
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
self.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
12
|
+
end
|
13
|
+
|
14
|
+
def use_transactional_fixtures
|
15
|
+
ActiveSupport::TestCase.use_transactional_fixtures
|
16
|
+
end
|
17
|
+
def use_transactional_fixtures=(value)
|
18
|
+
ActiveSupport::TestCase.use_transactional_fixtures = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def use_instantiated_fixtures
|
22
|
+
ActiveSupport::TestCase.use_instantiated_fixtures
|
23
|
+
end
|
24
|
+
def use_instantiated_fixtures=(value)
|
25
|
+
ActiveSupport::TestCase.use_instantiated_fixtures = value
|
26
|
+
end
|
27
|
+
|
28
|
+
def fixture_path
|
29
|
+
ActiveSupport::TestCase.fixture_path
|
30
|
+
end
|
31
|
+
def fixture_path=(path)
|
32
|
+
ActiveSupport::TestCase.fixture_path = path
|
33
|
+
end
|
34
|
+
|
35
|
+
def global_fixtures
|
36
|
+
ActiveSupport::TestCase.fixture_table_names
|
37
|
+
end
|
38
|
+
def global_fixtures=(fixtures)
|
39
|
+
ActiveSupport::TestCase.fixtures(*fixtures)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec'
|
2
|
+
|
3
|
+
require 'spec/rails/extensions/spec/runner/configuration'
|
4
|
+
require 'spec/rails/extensions/spec/matchers/have'
|
5
|
+
|
6
|
+
require 'spec/rails/extensions/active_support/test_case'
|
7
|
+
require 'spec/rails/extensions/active_record/base'
|
8
|
+
require 'spec/rails/extensions/action_controller/rescue'
|
9
|
+
require 'spec/rails/extensions/action_controller/test_case'
|
10
|
+
require 'spec/rails/extensions/action_controller/test_response'
|
11
|
+
require 'spec/rails/extensions/action_view/base'
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Spec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
class ArBeValid #:nodoc:
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@matcher = Spec::Matchers::Be.new :be_valid
|
9
|
+
@matcher.__send__ :handling_predicate!
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(actual)
|
13
|
+
@actual = actual
|
14
|
+
@matcher.matches? @actual
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should
|
18
|
+
if @actual.respond_to?(:errors) &&
|
19
|
+
ActiveRecord::Errors === @actual.errors
|
20
|
+
"Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")
|
21
|
+
else
|
22
|
+
@matcher.failure_message_for_should
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_message_for_should_not
|
27
|
+
@matcher.failure_message_for_should_not
|
28
|
+
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
"be valid"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# :call-seq:
|
36
|
+
# response.should be_valid
|
37
|
+
# response.should_not be_valid
|
38
|
+
def be_valid
|
39
|
+
ArBeValid.new
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,146 @@
|
|
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
|
+
|
9
|
+
def initialize(assertion, spec_scope, *args, &block)
|
10
|
+
@assertion = assertion
|
11
|
+
@spec_scope = spec_scope
|
12
|
+
@args = args
|
13
|
+
@block = block
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches?(response_or_text, &block)
|
17
|
+
@block = block if block
|
18
|
+
|
19
|
+
if doc = doc_from(response_or_text)
|
20
|
+
@args.unshift(doc)
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
@spec_scope.__send__(@assertion, *@args, &@block)
|
25
|
+
true
|
26
|
+
rescue ::Test::Unit::AssertionFailedError => @error
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def failure_message_for_should; @error.message; end
|
32
|
+
def failure_message_for_should_not; "should not #{description}, but did"; end
|
33
|
+
|
34
|
+
def description
|
35
|
+
{
|
36
|
+
:assert_select => "have tag#{format_args(*@args)}",
|
37
|
+
:assert_select_email => "send email#{format_args(*@args)}",
|
38
|
+
}[@assertion]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
module TestResponseOrString
|
44
|
+
def test_response?
|
45
|
+
ActionController::TestResponse === self and
|
46
|
+
!self.headers['Content-Type'].blank? and
|
47
|
+
self.headers['Content-Type'].to_sym == :xml
|
48
|
+
end
|
49
|
+
|
50
|
+
def string?
|
51
|
+
String === self
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def doc_from(response_or_text)
|
56
|
+
response_or_text.extend TestResponseOrString
|
57
|
+
markup = response_or_text.body if response_or_text.test_response?
|
58
|
+
markup = response_or_text if response_or_text.string?
|
59
|
+
HTML::Document.new(markup, false, response_or_text.test_response?).root if markup
|
60
|
+
end
|
61
|
+
|
62
|
+
def format_args(*args)
|
63
|
+
args.empty? ? "" : "(#{arg_list(*args)})"
|
64
|
+
end
|
65
|
+
|
66
|
+
def arg_list(*args)
|
67
|
+
args.map do |arg|
|
68
|
+
arg.respond_to?(:description) ? arg.description : arg.inspect
|
69
|
+
end.join(", ")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
# :call-seq:
|
75
|
+
# response.should have_tag(*args, &block)
|
76
|
+
# string.should have_tag(*args, &block)
|
77
|
+
#
|
78
|
+
# wrapper for assert_select with additional support for using
|
79
|
+
# css selectors to set expectation on Strings. Use this in
|
80
|
+
# helper specs, for example, to set expectations on the results
|
81
|
+
# of helper methods.
|
82
|
+
#
|
83
|
+
# == Examples
|
84
|
+
#
|
85
|
+
# # in a controller spec
|
86
|
+
# response.should have_tag("div", "some text")
|
87
|
+
#
|
88
|
+
# # in a helper spec (person_address_tag is a method in the helper)
|
89
|
+
# person_address_tag.should have_tag("input#person_address")
|
90
|
+
#
|
91
|
+
# see documentation for assert_select at http://api.rubyonrails.org/
|
92
|
+
def have_tag(*args, &block)
|
93
|
+
@__current_scope_for_assert_select = AssertSelect.new(:assert_select, self, *args, &block)
|
94
|
+
end
|
95
|
+
|
96
|
+
# wrapper for a nested assert_select
|
97
|
+
#
|
98
|
+
# response.should have_tag("div#form") do
|
99
|
+
# with_tag("input#person_name[name=?]", "person[name]")
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# see documentation for assert_select at http://api.rubyonrails.org/
|
103
|
+
def with_tag(*args, &block)
|
104
|
+
@__current_scope_for_assert_select.should have_tag(*args, &block)
|
105
|
+
end
|
106
|
+
|
107
|
+
# wrapper for a nested assert_select with false
|
108
|
+
#
|
109
|
+
# response.should have_tag("div#1") do
|
110
|
+
# without_tag("span", "some text that shouldn't be there")
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# see documentation for assert_select at http://api.rubyonrails.org/
|
114
|
+
def without_tag(*args, &block)
|
115
|
+
@__current_scope_for_assert_select.should_not have_tag(*args, &block)
|
116
|
+
end
|
117
|
+
|
118
|
+
# :call-seq:
|
119
|
+
# response.should have_rjs(*args, &block)
|
120
|
+
#
|
121
|
+
# wrapper for assert_select_rjs
|
122
|
+
#
|
123
|
+
# see documentation for assert_select_rjs at http://api.rubyonrails.org/
|
124
|
+
def have_rjs(*args, &block)
|
125
|
+
AssertSelect.new(:assert_select_rjs, self, *args, &block)
|
126
|
+
end
|
127
|
+
|
128
|
+
# :call-seq:
|
129
|
+
# response.should send_email(*args, &block)
|
130
|
+
#
|
131
|
+
# wrapper for assert_select_email
|
132
|
+
#
|
133
|
+
# see documentation for assert_select_email at http://api.rubyonrails.org/
|
134
|
+
def send_email(*args, &block)
|
135
|
+
AssertSelect.new(:assert_select_email, self, *args, &block)
|
136
|
+
end
|
137
|
+
|
138
|
+
# wrapper for assert_select_encoded
|
139
|
+
#
|
140
|
+
# see documentation for assert_select_encoded at http://api.rubyonrails.org/
|
141
|
+
def with_encoded(*args, &block)
|
142
|
+
should AssertSelect.new(:assert_select_encoded, self, *args, &block)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|