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,129 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Rails
|
3
|
-
module Matchers
|
4
|
-
|
5
|
-
class RenderTemplate #:nodoc:
|
6
|
-
|
7
|
-
def initialize(expected, controller)
|
8
|
-
@controller = controller
|
9
|
-
@expected = expected
|
10
|
-
end
|
11
|
-
|
12
|
-
def matches?(response_or_controller)
|
13
|
-
response = response_or_controller.respond_to?(:response) ?
|
14
|
-
response_or_controller.response :
|
15
|
-
response_or_controller
|
16
|
-
|
17
|
-
if response.respond_to?(:redirect?) && response.redirect?
|
18
|
-
@redirect_url = response.redirect_url
|
19
|
-
elsif response.respond_to?(:rendered_file)
|
20
|
-
@actual = response.rendered_file
|
21
|
-
elsif response.respond_to?(:rendered)
|
22
|
-
case template = response.rendered[:template]
|
23
|
-
when nil
|
24
|
-
unless response.rendered[:partials].empty?
|
25
|
-
@actual = path_and_file(response.rendered[:partials].keys.first).join("/_")
|
26
|
-
end
|
27
|
-
when ActionView::Template
|
28
|
-
@actual = template.path
|
29
|
-
when String
|
30
|
-
@actual = template
|
31
|
-
end
|
32
|
-
else
|
33
|
-
@actual = response.rendered_template.to_s
|
34
|
-
end
|
35
|
-
return false if @actual.blank?
|
36
|
-
given_controller_path, given_file = path_and_file(@actual)
|
37
|
-
expected_controller_path, expected_file = path_and_file(@expected)
|
38
|
-
given_controller_path == expected_controller_path && match_files(given_file, expected_file)
|
39
|
-
end
|
40
|
-
|
41
|
-
def match_files(actual, expected)
|
42
|
-
actual_parts = actual.split('.')
|
43
|
-
expected_parts = expected.split('.')
|
44
|
-
expected_parts.each_with_index do |expected_part, index|
|
45
|
-
return false unless expected_part == actual_parts[index]
|
46
|
-
end
|
47
|
-
true
|
48
|
-
end
|
49
|
-
|
50
|
-
def failure_message_for_should
|
51
|
-
if @redirect_url
|
52
|
-
"expected #{@expected.inspect}, got redirected to #{@redirect_url.inspect}"
|
53
|
-
else
|
54
|
-
"expected #{@expected.inspect}, got #{@actual.inspect}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def failure_message_for_should_not
|
59
|
-
"expected not to render #{@expected.inspect}, but did"
|
60
|
-
end
|
61
|
-
|
62
|
-
def description
|
63
|
-
"render template #{@expected.inspect}"
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
def path_and_file(path)
|
68
|
-
parts = path.split('/')
|
69
|
-
file = parts.pop
|
70
|
-
controller = parts.empty? ? current_controller_path : parts.join('/')
|
71
|
-
return controller, file
|
72
|
-
end
|
73
|
-
|
74
|
-
def controller_path_from(path)
|
75
|
-
parts = path.split('/')
|
76
|
-
parts.pop
|
77
|
-
parts.join('/')
|
78
|
-
end
|
79
|
-
|
80
|
-
def current_controller_path
|
81
|
-
@controller.class.to_s.underscore.gsub(/_controller$/,'')
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
# :call-seq:
|
87
|
-
# response.should render_template(template)
|
88
|
-
# response.should_not render_template(template)
|
89
|
-
#
|
90
|
-
# For use in controller code examples (integration or isolation mode).
|
91
|
-
#
|
92
|
-
# Passes if the specified template (view file) is rendered by the
|
93
|
-
# response. This file can be any view file, including a partial. However
|
94
|
-
# if it is a partial it must be rendered directly i.e. you can't detect
|
95
|
-
# that a partial has been rendered as part of a view using
|
96
|
-
# render_template. For that you should use a message expectation
|
97
|
-
# (mock) instead:
|
98
|
-
#
|
99
|
-
# controller.should_receive(:render).with(:partial => 'path/to/partial')
|
100
|
-
#
|
101
|
-
# <code>template</code> can include the controller path. It can also
|
102
|
-
# include an optional extension, which you only need to use when there
|
103
|
-
# is ambiguity.
|
104
|
-
#
|
105
|
-
# Note that partials must be spelled with the preceding underscore.
|
106
|
-
#
|
107
|
-
# == Examples
|
108
|
-
#
|
109
|
-
# response.should render_template('list')
|
110
|
-
# response.should render_template('same_controller/list')
|
111
|
-
# response.should render_template('other_controller/list')
|
112
|
-
#
|
113
|
-
# # with extensions
|
114
|
-
# response.should render_template('list.rjs')
|
115
|
-
# response.should render_template('list.haml')
|
116
|
-
# response.should render_template('same_controller/list.rjs')
|
117
|
-
# response.should render_template('other_controller/list.rjs')
|
118
|
-
#
|
119
|
-
# # partials
|
120
|
-
# response.should render_template('_a_partial')
|
121
|
-
# response.should render_template('same_controller/_a_partial')
|
122
|
-
# response.should render_template('other_controller/_a_partial')
|
123
|
-
def render_template(path)
|
124
|
-
RenderTemplate.new(path.to_s, @controller)
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'rack/utils'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Rails
|
5
|
-
module Matchers
|
6
|
-
USAGE = ArgumentError.new( 'usage: { :method => "path" }.should route_to( :controller => "controller", :action => "action", [ args ] )' )
|
7
|
-
|
8
|
-
class PathDecomposer
|
9
|
-
def self.decompose_path(path)
|
10
|
-
method, path = if Hash === path
|
11
|
-
raise USAGE if path.keys.size > 1
|
12
|
-
path.entries.first
|
13
|
-
else
|
14
|
-
[:get, path]
|
15
|
-
end
|
16
|
-
path, querystring = path.split('?')
|
17
|
-
return method, path, querystring
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class RouteTo #:nodoc:
|
22
|
-
def initialize(expected, example)
|
23
|
-
@route, @example = expected,example
|
24
|
-
end
|
25
|
-
|
26
|
-
def matches?(path)
|
27
|
-
begin
|
28
|
-
@actual = path
|
29
|
-
method, path, querystring = PathDecomposer.decompose_path(path)
|
30
|
-
params = querystring.blank? ? {} : Rack::Utils.parse_query(querystring).symbolize_keys!
|
31
|
-
@example.assert_routing({ :method => method, :path => path }, @route, {}, params)
|
32
|
-
true
|
33
|
-
rescue ActionController::RoutingError, ::Test::Unit::AssertionFailedError, ActionController::MethodNotAllowed => e
|
34
|
-
raise e.class, "#{e}\nIf you're expecting this failure, we suggest { :#{method} => \"#{path}\" }.should_not be_routable"
|
35
|
-
rescue Exception => e
|
36
|
-
raise e.class, "#{e}\n#{e.backtrace.join( "\n" )}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def does_not_match(path)
|
41
|
-
raise ArgumentError, "Don't test a negative route like this."
|
42
|
-
end
|
43
|
-
|
44
|
-
def failure_message_for_should
|
45
|
-
"Expected #{@expected.inspect} to route to #{@actual.inspect}, but it didn't.\n"+
|
46
|
-
"In this case, we expected you to get an exception. So this message probably means something weird happened."
|
47
|
-
end
|
48
|
-
|
49
|
-
def failure_message_for_should_not
|
50
|
-
"Expected a routing error, but the route passed instead. \nNote, when expecting routes to fail, you should use 'should_not be_routable' instead."
|
51
|
-
end
|
52
|
-
|
53
|
-
def description
|
54
|
-
"route to #{@expected.inspect}"
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
attr_reader :expected
|
59
|
-
attr_reader :actual
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
# :call-seq:
|
64
|
-
# "path".should route_to(expected) # assumes GET
|
65
|
-
# { :get => "path" }.should route_to(expected)
|
66
|
-
# { :put => "path" }.should route_to(expected)
|
67
|
-
#
|
68
|
-
# Uses ActionController::Routing::Routes to verify that
|
69
|
-
# the path-and-method routes to a given set of options.
|
70
|
-
# Also verifies route-generation, so that the expected options
|
71
|
-
# do generate a pathname consisten with the indicated path/method.
|
72
|
-
#
|
73
|
-
# For negative tests, only the route recognition failure can be
|
74
|
-
# tested; since route generation via path_to() will always generate
|
75
|
-
# a path as requested. Use .should_not be_routable() in this case.
|
76
|
-
#
|
77
|
-
# == Examples
|
78
|
-
# { :get => '/registrations/1/edit' }.
|
79
|
-
# should route_to(:controller => 'registrations', :action => 'edit', :id => '1')
|
80
|
-
# { :put => "/registrations/1" }.should
|
81
|
-
# route_to(:controller => 'registrations', :action => 'update', :id => 1)
|
82
|
-
# { :post => "/registrations/" }.should
|
83
|
-
# route_to(:controller => 'registrations', :action => 'create')
|
84
|
-
|
85
|
-
def route_to(expected)
|
86
|
-
RouteTo.new(expected, self)
|
87
|
-
end
|
88
|
-
|
89
|
-
class BeRoutable
|
90
|
-
def initialize(example)
|
91
|
-
@example = example
|
92
|
-
end
|
93
|
-
|
94
|
-
def matches?(path)
|
95
|
-
begin
|
96
|
-
@actual = path
|
97
|
-
method, path = PathDecomposer.decompose_path(path)
|
98
|
-
@example.assert_recognizes({}, { :method => method, :path => path }, {} )
|
99
|
-
true
|
100
|
-
rescue ActionController::RoutingError, ActionController::MethodNotAllowed
|
101
|
-
false
|
102
|
-
rescue ::Test::Unit::AssertionFailedError => e
|
103
|
-
# the second thingy will always be "<{}>" becaues of the way we called assert_recognizes({}...) above.
|
104
|
-
e.to_s =~ /<(.*)> did not match <\{\}>/ and @actual_place = $1 or raise
|
105
|
-
true
|
106
|
-
end
|
107
|
-
end
|
108
|
-
def failure_message_for_should
|
109
|
-
"Expected '#{@actual.keys.first.to_s.upcase} #{@actual.values.first}' to be routable, but it wasn't.\n"+
|
110
|
-
"To really test routability, we recommend #{@actual.inspect}.\n"+
|
111
|
-
" should route_to( :action => 'action', :controller => 'controller' )\n\n"+
|
112
|
-
|
113
|
-
"That way, you'll verify where your route goes to. Plus, we'll verify\n"+
|
114
|
-
"the generation of the expected path from the action/controller, as in\n"+
|
115
|
-
"the url_for() helper."
|
116
|
-
end
|
117
|
-
|
118
|
-
def failure_message_for_should_not
|
119
|
-
"Expected '#{@actual.keys.first.to_s.upcase} #{@actual.values.first}' to fail, but it routed to #{@actual_place} instead"
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
# :call-seq:
|
124
|
-
# { "path" }.should_not be_routable # assumes GET
|
125
|
-
# { :get => "path" }.should_not be_routable
|
126
|
-
# { :put => "path" }.should_not be_routable
|
127
|
-
#
|
128
|
-
# Uses ActionController::Routing::Routes to verify that
|
129
|
-
# the path-and-method cannot be routed to a controller.
|
130
|
-
# Since url_for() will always generate a path, even if that
|
131
|
-
# path is not routable, the negative test only needs to be
|
132
|
-
# performed on the route recognition.
|
133
|
-
#
|
134
|
-
# Don't use this matcher for testing expected routability -
|
135
|
-
# use .should route_to( :controller => "controller", :action => "action" ) instead
|
136
|
-
#
|
137
|
-
# == Examples
|
138
|
-
# { :get => '/registrations/1/attendees/3/edit' }.should_not be_routable
|
139
|
-
# { :get => '/attendees/3/edit' }.should route_to( ...<controller/action>... )
|
140
|
-
|
141
|
-
def be_routable
|
142
|
-
BeRoutable.new(self)
|
143
|
-
end
|
144
|
-
|
145
|
-
alias_method :be_routeable, :be_routable
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
data/lib/spec/rails/mocks.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Rails
|
3
|
-
|
4
|
-
class IllegalDataAccessException < StandardError; end
|
5
|
-
|
6
|
-
module Mocks
|
7
|
-
|
8
|
-
# Creates a mock object instance for a +model_class+ with common
|
9
|
-
# methods stubbed out. Additional methods may be easily stubbed (via
|
10
|
-
# add_stubs) if +stubs+ is passed.
|
11
|
-
def mock_model(model_class, options_and_stubs = {})
|
12
|
-
id = options_and_stubs[:id] || next_id
|
13
|
-
options_and_stubs = options_and_stubs.reverse_merge({
|
14
|
-
:id => id,
|
15
|
-
:to_param => id.to_s,
|
16
|
-
:new_record? => false,
|
17
|
-
:destroyed? => false,
|
18
|
-
:marked_for_destruction? => false,
|
19
|
-
:errors => stub("errors", :count => 0)
|
20
|
-
})
|
21
|
-
m = mock("#{model_class.name}_#{id}", options_and_stubs)
|
22
|
-
m.__send__(:__mock_proxy).instance_eval <<-CODE
|
23
|
-
def @target.as_new_record
|
24
|
-
self.stub(:id).and_return nil
|
25
|
-
self.stub(:to_param).and_return nil
|
26
|
-
self.stub(:new_record?).and_return true
|
27
|
-
self
|
28
|
-
end
|
29
|
-
def @target.to_str
|
30
|
-
self.to_s
|
31
|
-
end
|
32
|
-
def @target.is_a?(other)
|
33
|
-
#{model_class}.ancestors.include?(other)
|
34
|
-
end
|
35
|
-
def @target.kind_of?(other)
|
36
|
-
#{model_class}.ancestors.include?(other)
|
37
|
-
end
|
38
|
-
def @target.instance_of?(other)
|
39
|
-
other == #{model_class}
|
40
|
-
end
|
41
|
-
def @target.class
|
42
|
-
#{model_class}
|
43
|
-
end
|
44
|
-
CODE
|
45
|
-
yield m if block_given?
|
46
|
-
m
|
47
|
-
end
|
48
|
-
|
49
|
-
module ModelStubber
|
50
|
-
def connection
|
51
|
-
raise Spec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
|
52
|
-
end
|
53
|
-
def new_record?
|
54
|
-
id.nil?
|
55
|
-
end
|
56
|
-
def as_new_record
|
57
|
-
self.id = nil
|
58
|
-
self
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# :call-seq:
|
63
|
-
# stub_model(Model)
|
64
|
-
# stub_model(Model).as_new_record
|
65
|
-
# stub_model(Model, hash_of_stubs)
|
66
|
-
# stub_model(Model, instance_variable_name, hash_of_stubs)
|
67
|
-
#
|
68
|
-
# Creates an instance of +Model+ that is prohibited from accessing the
|
69
|
-
# database*. For each key in +hash_of_stubs+, if the model has a
|
70
|
-
# matching attribute (determined by asking it) are simply assigned the
|
71
|
-
# submitted values. If the model does not have a matching attribute, the
|
72
|
-
# key/value pair is assigned as a stub return value using RSpec's
|
73
|
-
# mocking/stubbing framework.
|
74
|
-
#
|
75
|
-
# <tt>new_record?</tt> is overridden to return the result of id.nil?
|
76
|
-
# This means that by default new_record? will return false. If you want
|
77
|
-
# the object to behave as a new record, sending it +as_new_record+ will
|
78
|
-
# set the id to nil. You can also explicitly set :id => nil, in which
|
79
|
-
# case new_record? will return true, but using +as_new_record+ makes the
|
80
|
-
# example a bit more descriptive.
|
81
|
-
#
|
82
|
-
# While you can use stub_model in any example (model, view, controller,
|
83
|
-
# helper), it is especially useful in view examples, which are
|
84
|
-
# inherently more state-based than interaction-based.
|
85
|
-
#
|
86
|
-
# == Database Independence
|
87
|
-
#
|
88
|
-
# +stub_model+ does not make your examples entirely
|
89
|
-
# database-independent. It does not stop the model class itself from
|
90
|
-
# loading up its columns from the database. It just prevents data access
|
91
|
-
# from the object itself. To completely decouple from the database, take
|
92
|
-
# a look at libraries like unit_record or NullDB.
|
93
|
-
#
|
94
|
-
# == Examples
|
95
|
-
#
|
96
|
-
# stub_model(Person)
|
97
|
-
# stub_model(Person).as_new_record
|
98
|
-
# stub_model(Person, :id => 37)
|
99
|
-
# stub_model(Person) do |person|
|
100
|
-
# person.first_name = "David"
|
101
|
-
# end
|
102
|
-
def stub_model(model_class, stubs={})
|
103
|
-
stubs = {:id => next_id}.merge(stubs)
|
104
|
-
model_class.new.tap do |model|
|
105
|
-
model.id = stubs.delete(:id)
|
106
|
-
model.extend ModelStubber
|
107
|
-
stubs.each do |k,v|
|
108
|
-
if model.has_attribute?(k)
|
109
|
-
model[k] = stubs.delete(k)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
model.stub!(stubs)
|
113
|
-
yield model if block_given?
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# DEPRECATED - use object.stub!(:method => value, :method2 => value)
|
118
|
-
#
|
119
|
-
# Stubs methods on +object+ (if +object+ is a symbol or string a new mock
|
120
|
-
# with that name will be created). +stubs+ is a Hash of +method=>value+
|
121
|
-
def add_stubs(object, stubs = {}) #:nodoc:
|
122
|
-
Kernel.warn <<-WARNING
|
123
|
-
DEPRECATION NOTICE: add_stubs is deprecated and will be removed
|
124
|
-
from a future version of rspec-rails. Use this instead:
|
125
|
-
|
126
|
-
object.stub!(:method => value, :method2 => value)
|
127
|
-
|
128
|
-
WARNING
|
129
|
-
object.stub!(stubs)
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
@@model_id = 1000
|
134
|
-
def next_id
|
135
|
-
@@model_id += 1
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
data/lib/spec/rails/version.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Spec # :nodoc:
|
2
|
-
module Rails # :nodoc:
|
3
|
-
module VERSION # :nodoc:
|
4
|
-
unless defined? MAJOR
|
5
|
-
MAJOR = 1
|
6
|
-
MINOR = 3
|
7
|
-
TINY = 4
|
8
|
-
PRE = nil
|
9
|
-
|
10
|
-
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
11
|
-
|
12
|
-
SUMMARY = "rspec-rails #{STRING}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../../lib/autotest/rails_rspec'
|
3
|
-
require File.dirname(__FILE__) + '/../../../rspec/spec/autotest/autotest_matchers'
|
4
|
-
|
5
|
-
describe Autotest::RailsRspec, "file mapping" do
|
6
|
-
before(:each) do
|
7
|
-
@autotest = Autotest::RailsRspec.new
|
8
|
-
@autotest.hook :initialize
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should map model example to model" do
|
12
|
-
@autotest.should map_specs(['spec/models/thing_spec.rb']).
|
13
|
-
to('app/models/thing.rb')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should map controller example to controller" do
|
17
|
-
@autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
|
18
|
-
to('app/controllers/things_controller.rb')
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should map view.rhtml" do
|
22
|
-
@autotest.should map_specs(['spec/views/things/index.rhtml_spec.rb']).
|
23
|
-
to('app/views/things/index.rhtml')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should map view.rhtml with underscores in example filename" do
|
27
|
-
@autotest.should map_specs(['spec/views/things/index_rhtml_spec.rb']).
|
28
|
-
to('app/views/things/index.rhtml')
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should map view.html.erb" do
|
32
|
-
@autotest.should map_specs(['spec/views/things/index.html.erb_spec.rb']).
|
33
|
-
to('app/views/things/index.html.erb')
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "between routes.rb and things which depend on routes" do
|
37
|
-
it "should map routes.rb to controllers" do
|
38
|
-
@autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
|
39
|
-
to('config/routes.rb')
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should map routes.rb to views" do
|
43
|
-
@autotest.should map_specs(['spec/views/things/action.html.erb_spec.rb']).
|
44
|
-
to('config/routes.rb')
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should map routes.rb to helpers" do
|
48
|
-
@autotest.should map_specs(['spec/helpers/things_helper_spec.rb']).
|
49
|
-
to('config/routes.rb')
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should map routing example to routes" do
|
53
|
-
@autotest.should map_specs(['spec/routing/thing_spec.rb']).
|
54
|
-
to('config/routes.rb')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "between the config and specs" do
|
59
|
-
['spec/controllers/things_controller_spec.rb',
|
60
|
-
'spec/views/things/action.html.erb_spec.rb',
|
61
|
-
'spec/helpers/things_helper_spec.rb',
|
62
|
-
'spec/routing/thing_spec.rb',
|
63
|
-
'spec/models/thing_spec.rb'].each do |file_path|
|
64
|
-
|
65
|
-
it "should map environment.rb to #{file_path}" do
|
66
|
-
@autotest.should map_specs([file_path]).
|
67
|
-
to('config/environment.rb')
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should map environments/test.rb to #{file_path}" do
|
71
|
-
@autotest.should map_specs([file_path]).
|
72
|
-
to('config/environments/test.rb')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should map boot.rb to #{file_path}" do
|
76
|
-
@autotest.should map_specs([file_path]).
|
77
|
-
to('config/boot.rb')
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should map spec_helper.rb to #{file_path}" do
|
81
|
-
@autotest.should map_specs([file_path]).
|
82
|
-
to('spec/spec_helper.rb')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|