rspec-rails 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -1
- data/Capybara.md +1 -3
- data/Changelog.md +126 -58
- data/README.md +31 -4
- data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
- data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
- data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
- data/lib/rspec/rails.rb +1 -8
- data/lib/rspec/rails/configuration.rb +72 -0
- data/lib/rspec/rails/example.rb +0 -64
- data/lib/rspec/rails/example/controller_example_group.rb +16 -12
- data/lib/rspec/rails/example/feature_example_group.rb +0 -2
- data/lib/rspec/rails/example/helper_example_group.rb +0 -2
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/request_example_group.rb +0 -2
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/view_example_group.rb +1 -2
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/fixture_support.rb +0 -8
- data/lib/rspec/rails/matchers.rb +1 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
- data/lib/rspec/rails/tasks/rspec.rake +12 -5
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +6 -34
- metadata +42 -316
- metadata.gz.sig +0 -0
- data/features/Generators.md +0 -25
- data/features/GettingStarted.md +0 -84
- data/features/README.md +0 -48
- data/features/RailsVersions.md +0 -4
- data/features/Transactions.md +0 -84
- data/features/Upgrade.md +0 -121
- data/features/controller_specs/Cookies.md +0 -57
- data/features/controller_specs/README.md +0 -45
- data/features/controller_specs/anonymous_controller.feature +0 -436
- data/features/controller_specs/bypass_rescue.feature +0 -75
- data/features/controller_specs/controller_spec.feature +0 -58
- data/features/controller_specs/engine_routes.feature +0 -51
- data/features/controller_specs/isolation_from_views.feature +0 -87
- data/features/controller_specs/render_views.feature +0 -114
- data/features/directory_structure.feature +0 -71
- data/features/feature_specs/feature_spec.feature +0 -35
- data/features/helper_specs/helper_spec.feature +0 -122
- data/features/mailer_specs/url_helpers.feature +0 -38
- data/features/matchers/README.md +0 -18
- data/features/matchers/new_record_matcher.feature +0 -41
- data/features/matchers/redirect_to_matcher.feature +0 -40
- data/features/matchers/relation_match_array.feature +0 -27
- data/features/matchers/render_template_matcher.feature +0 -49
- data/features/mocks/mock_model.feature +0 -147
- data/features/mocks/stub_model.feature +0 -58
- data/features/model_specs/README.md +0 -21
- data/features/model_specs/errors_on.feature +0 -51
- data/features/model_specs/records.feature +0 -27
- data/features/model_specs/transactional_examples.feature +0 -109
- data/features/request_specs/request_spec.feature +0 -49
- data/features/routing_specs/README.md +0 -16
- data/features/routing_specs/be_routable_matcher.feature +0 -80
- data/features/routing_specs/engine_routes.feature +0 -38
- data/features/routing_specs/named_routes.feature +0 -18
- data/features/routing_specs/route_to_matcher.feature +0 -90
- data/features/step_definitions/additional_cli_steps.rb +0 -4
- data/features/step_definitions/model_steps.rb +0 -3
- data/features/support/capybara.rb +0 -7
- data/features/support/env.rb +0 -53
- data/features/support/rails_versions.rb +0 -4
- data/features/support/rubinius.rb +0 -6
- data/features/view_specs/inferred_controller_path.feature +0 -45
- data/features/view_specs/stub_template.feature +0 -51
- data/features/view_specs/view_spec.feature +0 -206
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/mocks.rb +0 -272
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
- data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
- data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
- data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
- data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
- data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
- data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
- data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
- data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
- data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
- data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
- data/spec/rspec/rails/configuration_spec.rb +0 -26
- data/spec/rspec/rails/deprecations_spec.rb +0 -18
- data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
- data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
- data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
- data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
- data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
- data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
- data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
- data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
- data/spec/rspec/rails/fixture_support_spec.rb +0 -17
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
- data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
- data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
- data/spec/rspec/rails/matchers/has_spec.rb +0 -29
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
- data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
- data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
- data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
- data/spec/rspec/rails/view_rendering_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -33
- data/spec/support/ar_classes.rb +0 -42
- data/spec/support/helpers.rb +0 -34
- data/spec/support/matchers.rb +0 -9
- data/spec/support/null_object.rb +0 -6
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>" do
|
3
|
+
describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>", :type => :view do
|
4
4
|
pending "add some examples to (or delete) #{__FILE__}"
|
5
5
|
end
|
@@ -12,7 +12,12 @@ require 'rspec/rails'
|
|
12
12
|
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
13
13
|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
14
14
|
|
15
|
-
<% if ::Rails::VERSION::STRING >= '4' -%>
|
15
|
+
<% if ::Rails::VERSION::STRING >= '4.1' -%>
|
16
|
+
# Checks for pending migrations before tests are run.
|
17
|
+
# If you are not using ActiveRecord, you can remove this line.
|
18
|
+
ActiveRecord::Migration.maintain_test_schema!
|
19
|
+
|
20
|
+
<% elsif ::Rails::VERSION::STRING >= '4' -%>
|
16
21
|
# Checks for pending migrations before tests are run.
|
17
22
|
# If you are not using ActiveRecord, you can remove this line.
|
18
23
|
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
@@ -40,4 +45,19 @@ RSpec.configure do |config|
|
|
40
45
|
# the seed, which is printed after each run.
|
41
46
|
# --seed 1234
|
42
47
|
config.order = "random"
|
48
|
+
|
49
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
50
|
+
# based on their file location, for example enabling you to call `get` and
|
51
|
+
# `post` in specs under `spec/controllers`.
|
52
|
+
#
|
53
|
+
# You can disable this behaviour by removing the line below, and instead
|
54
|
+
# explictly tag your specs with their type, e.g.:
|
55
|
+
#
|
56
|
+
# describe UsersController, :type => :controller do
|
57
|
+
# # ...
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# The different available types are documented in the features, such as in
|
61
|
+
# https://relishapp.com/rspec/rspec-rails/v/3-0/docs
|
62
|
+
config.infer_spec_type_from_file_location!
|
43
63
|
end
|
@@ -19,7 +19,7 @@ require 'spec_helper'
|
|
19
19
|
# that an instance is receiving a specific message.
|
20
20
|
|
21
21
|
<% module_namespacing do -%>
|
22
|
-
describe <%= controller_class_name %>Controller do
|
22
|
+
describe <%= controller_class_name %>Controller, :type => :controller do
|
23
23
|
|
24
24
|
# This should return the minimal set of attributes required to create a valid
|
25
25
|
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
@@ -134,7 +134,11 @@ describe <%= controller_class_name %>Controller do
|
|
134
134
|
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
135
135
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
136
|
# Trigger the behavior that occurs when invalid params are submitted
|
137
|
-
|
137
|
+
<%- if ::Rails::VERSION::STRING >= '4' -%>
|
138
|
+
allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
|
139
|
+
<%- else -%>
|
140
|
+
allow_any_instance_of(<%= class_name %>).to receive(:update_attributes).and_return(false)
|
141
|
+
<%- end -%>
|
138
142
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
139
143
|
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
140
144
|
end
|
@@ -142,7 +146,11 @@ describe <%= controller_class_name %>Controller do
|
|
142
146
|
it "re-renders the 'edit' template" do
|
143
147
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
144
148
|
# Trigger the behavior that occurs when invalid params are submitted
|
145
|
-
|
149
|
+
<%- if ::Rails::VERSION::STRING >= '4' -%>
|
150
|
+
allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
|
151
|
+
<%- else -%>
|
152
|
+
allow_any_instance_of(<%= class_name %>).to receive(:update_attributes).and_return(false)
|
153
|
+
<%- end -%>
|
146
154
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
147
155
|
expect(response).to render_template("edit")
|
148
156
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/edit" do
|
4
|
+
describe "<%= ns_table_name %>/edit", :type => :view do
|
5
5
|
before(:each) do
|
6
|
-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>,
|
6
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
@@ -15,7 +15,8 @@ describe "<%= ns_table_name %>/edit" do
|
|
15
15
|
|
16
16
|
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
|
17
17
|
<% for attribute in output_attributes -%>
|
18
|
-
|
18
|
+
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
19
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
19
20
|
<% end -%>
|
20
21
|
end
|
21
22
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/index" do
|
4
|
+
describe "<%= ns_table_name %>/index", :type => :view do
|
5
5
|
before(:each) do
|
6
6
|
assign(:<%= table_name %>, [
|
7
7
|
<% [1,2].each_with_index do |id, model_index| -%>
|
8
|
-
|
8
|
+
<%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
|
9
9
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
10
10
|
:<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
11
11
|
<% end -%>
|
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/new" do
|
4
|
+
describe "<%= ns_table_name %>/new", :type => :view do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%= ns_file_name %>,
|
6
|
+
assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
10
|
-
<%= !output_attributes.empty? ? " )
|
10
|
+
<%= !output_attributes.empty? ? " ))\n end" : " end" %>
|
11
11
|
|
12
12
|
it "renders new <%= ns_file_name %> form" do
|
13
13
|
render
|
14
14
|
|
15
15
|
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
|
16
16
|
<% for attribute in output_attributes -%>
|
17
|
-
|
17
|
+
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
18
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
18
19
|
<% end -%>
|
19
20
|
end
|
20
21
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/show" do
|
4
|
+
describe "<%= ns_table_name %>/show", :type => :view do
|
5
5
|
before(:each) do
|
6
|
-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>,
|
6
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
:<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
data/lib/rspec/rails.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
require 'rspec/core'
|
2
|
-
require 'rspec/collection_matchers'
|
3
|
-
|
4
|
-
RSpec::configure do |c|
|
5
|
-
c.backtrace_exclusion_patterns << /vendor\//
|
6
|
-
c.backtrace_exclusion_patterns << /lib\/rspec\/rails/
|
7
|
-
end
|
8
|
-
|
9
2
|
require 'rails/version'
|
10
3
|
require 'rspec/rails/extensions'
|
11
4
|
require 'rspec/rails/view_rendering'
|
12
5
|
require 'rspec/rails/adapters'
|
13
6
|
require 'rspec/rails/matchers'
|
14
7
|
require 'rspec/rails/fixture_support'
|
15
|
-
require 'rspec/rails/mocks'
|
16
8
|
require 'rspec/rails/example'
|
17
9
|
require 'rspec/rails/vendor/capybara'
|
10
|
+
require 'rspec/rails/configuration'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @private
|
4
|
+
def self.initialize_configuration(config)
|
5
|
+
config.backtrace_exclusion_patterns << /vendor\//
|
6
|
+
config.backtrace_exclusion_patterns << /lib\/rspec\/rails/
|
7
|
+
|
8
|
+
config.include RSpec::Rails::ControllerExampleGroup, :type => :controller
|
9
|
+
config.include RSpec::Rails::HelperExampleGroup, :type => :helper
|
10
|
+
config.include RSpec::Rails::ModelExampleGroup, :type => :model
|
11
|
+
config.include RSpec::Rails::RequestExampleGroup, :type => :request
|
12
|
+
config.include RSpec::Rails::RoutingExampleGroup, :type => :routing
|
13
|
+
config.include RSpec::Rails::ViewExampleGroup, :type => :view
|
14
|
+
config.include RSpec::Rails::FeatureExampleGroup, :type => :feature
|
15
|
+
|
16
|
+
if defined?(RSpec::Rails::MailerExampleGroup)
|
17
|
+
config.include RSpec::Rails::MailerExampleGroup, :type => :mailer
|
18
|
+
end
|
19
|
+
|
20
|
+
# controller settings
|
21
|
+
config.add_setting :infer_base_class_for_anonymous_controllers, :default => true
|
22
|
+
|
23
|
+
# fixture support
|
24
|
+
config.include RSpec::Rails::FixtureSupport
|
25
|
+
config.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
|
26
|
+
config.add_setting :use_instantiated_fixtures
|
27
|
+
config.add_setting :global_fixtures
|
28
|
+
config.add_setting :fixture_path
|
29
|
+
|
30
|
+
# view rendering settings
|
31
|
+
# This allows us to expose `render_views` as a config option even though it
|
32
|
+
# breaks the convention of other options by using `render_views` as a
|
33
|
+
# command (i.e. render_views = true), where it would normally be used as a
|
34
|
+
# getter. This makes it easier for rspec-rails users because we use
|
35
|
+
# `render_views` directly in example groups, so this aligns the two APIs,
|
36
|
+
# but requires this workaround:
|
37
|
+
config.add_setting :rendering_views, :default => false
|
38
|
+
|
39
|
+
def config.render_views=(val)
|
40
|
+
self.rendering_views = val
|
41
|
+
end
|
42
|
+
|
43
|
+
def config.render_views
|
44
|
+
self.rendering_views = true
|
45
|
+
end
|
46
|
+
|
47
|
+
def config.render_views?
|
48
|
+
rendering_views
|
49
|
+
end
|
50
|
+
|
51
|
+
def config.infer_spec_type_from_file_location!
|
52
|
+
{
|
53
|
+
:controller => %w[spec controllers],
|
54
|
+
:helper => %w[spec helpers],
|
55
|
+
:mailer => %w[spec mailers],
|
56
|
+
:model => %w[spec models],
|
57
|
+
:request => %w[spec (requests|integration|api)],
|
58
|
+
:routing => %w[spec routing],
|
59
|
+
:view => %w[spec views],
|
60
|
+
:feature => %w[spec features]
|
61
|
+
}.each do |type, dir_parts|
|
62
|
+
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
|
63
|
+
define_derived_metadata(:file_path => escaped_path) do |metadata|
|
64
|
+
metadata[:type] ||= type
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
initialize_configuration RSpec.configuration
|
71
|
+
end
|
72
|
+
end
|
data/lib/rspec/rails/example.rb
CHANGED
@@ -7,67 +7,3 @@ require 'rspec/rails/example/mailer_example_group'
|
|
7
7
|
require 'rspec/rails/example/routing_example_group'
|
8
8
|
require 'rspec/rails/example/model_example_group'
|
9
9
|
require 'rspec/rails/example/feature_example_group'
|
10
|
-
|
11
|
-
RSpec::configure do |c|
|
12
|
-
def c.escaped_path(*parts)
|
13
|
-
Regexp.compile(parts.join('[\\\/]') + '[\\\/]')
|
14
|
-
end
|
15
|
-
|
16
|
-
controller_path_regex = c.escaped_path(%w[spec controllers])
|
17
|
-
c.include RSpec::Rails::ControllerExampleGroup,
|
18
|
-
:type => :controller,
|
19
|
-
:example_group => lambda { |example_group, metadata|
|
20
|
-
metadata[:type].nil? && controller_path_regex =~ example_group[:file_path]
|
21
|
-
}
|
22
|
-
|
23
|
-
helper_path_regex = c.escaped_path(%w[spec helpers])
|
24
|
-
c.include RSpec::Rails::HelperExampleGroup,
|
25
|
-
:type => :helper,
|
26
|
-
:example_group => lambda { |example_group, metadata|
|
27
|
-
metadata[:type].nil? && helper_path_regex =~ example_group[:file_path]
|
28
|
-
}
|
29
|
-
|
30
|
-
mailer_path_regex = c.escaped_path(%w[spec mailers])
|
31
|
-
if defined?(RSpec::Rails::MailerExampleGroup)
|
32
|
-
c.include RSpec::Rails::MailerExampleGroup,
|
33
|
-
:type => :mailer,
|
34
|
-
:example_group => lambda { |example_group, metadata|
|
35
|
-
metadata[:type].nil? && mailer_path_regex =~ example_group[:file_path]
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
model_path_regex = c.escaped_path(%w[spec models])
|
40
|
-
c.include RSpec::Rails::ModelExampleGroup,
|
41
|
-
:type => :model,
|
42
|
-
:example_group => lambda { |example_group, metadata|
|
43
|
-
metadata[:type].nil? && model_path_regex =~ example_group[:file_path]
|
44
|
-
}
|
45
|
-
|
46
|
-
request_path_regex = c.escaped_path(%w[spec (requests|integration|api)])
|
47
|
-
c.include RSpec::Rails::RequestExampleGroup,
|
48
|
-
:type => :request,
|
49
|
-
:example_group => lambda { |example_group, metadata|
|
50
|
-
metadata[:type].nil? && request_path_regex =~ example_group[:file_path]
|
51
|
-
}
|
52
|
-
|
53
|
-
routing_path_regex = c.escaped_path(%w[spec routing])
|
54
|
-
c.include RSpec::Rails::RoutingExampleGroup,
|
55
|
-
:type => :routing,
|
56
|
-
:example_group => lambda { |example_group, metadata|
|
57
|
-
metadata[:type].nil? && routing_path_regex =~ example_group[:file_path]
|
58
|
-
}
|
59
|
-
|
60
|
-
view_path_regex = c.escaped_path(%w[spec views])
|
61
|
-
c.include RSpec::Rails::ViewExampleGroup,
|
62
|
-
:type => :view,
|
63
|
-
:example_group => lambda { |example_group, metadata|
|
64
|
-
metadata[:type].nil? && view_path_regex =~ example_group[:file_path]
|
65
|
-
}
|
66
|
-
|
67
|
-
feature_example_regex = c.escaped_path(%w[spec features])
|
68
|
-
c.include RSpec::Rails::FeatureExampleGroup,
|
69
|
-
:type => :feature,
|
70
|
-
:example_group => lambda { |example_group, metadata|
|
71
|
-
metadata[:type].nil? && feature_example_regex =~ example_group[:file_path]
|
72
|
-
}
|
73
|
-
end
|
@@ -1,7 +1,3 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.add_setting :infer_base_class_for_anonymous_controllers, :default => true
|
3
|
-
end
|
4
|
-
|
5
1
|
module RSpec::Rails
|
6
2
|
module ControllerExampleGroup
|
7
3
|
extend ActiveSupport::Concern
|
@@ -60,7 +56,7 @@ module RSpec::Rails
|
|
60
56
|
end
|
61
57
|
base_class ||= defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
62
58
|
|
63
|
-
|
59
|
+
new_controller_class = Class.new(base_class) do
|
64
60
|
def self.name
|
65
61
|
root_controller = defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
66
62
|
if superclass == root_controller || superclass.abstract?
|
@@ -70,15 +66,25 @@ module RSpec::Rails
|
|
70
66
|
end
|
71
67
|
end
|
72
68
|
end
|
73
|
-
|
69
|
+
new_controller_class.class_eval(&body)
|
70
|
+
(class << self; self; end).__send__(:define_method, :controller_class) { new_controller_class }
|
74
71
|
|
75
72
|
before do
|
76
73
|
@orig_routes = self.routes
|
77
74
|
resource_name = @controller.respond_to?(:controller_name) ?
|
78
75
|
@controller.controller_name.to_sym : :anonymous
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
resource_path = @controller.respond_to?(:controller_path) ?
|
77
|
+
@controller.controller_path : resource_name.to_s
|
78
|
+
resource_module = resource_path.rpartition('/').first.presence
|
79
|
+
resource_as = 'anonymous_' + resource_path.tr('/', '_')
|
80
|
+
self.routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
81
|
+
r.draw do
|
82
|
+
resources resource_name,
|
83
|
+
:as => resource_as,
|
84
|
+
:module => resource_module,
|
85
|
+
:path => resource_path
|
86
|
+
end
|
87
|
+
end
|
82
88
|
end
|
83
89
|
|
84
90
|
after do
|
@@ -119,7 +125,7 @@ module RSpec::Rails
|
|
119
125
|
end
|
120
126
|
|
121
127
|
# Extends the controller with a module that overrides
|
122
|
-
# `rescue_with_handler` to raise the exception passed to it.
|
128
|
+
# `rescue_with_handler` to raise the exception passed to it. Use this to
|
123
129
|
# specify that an action _should_ raise an exception given appropriate
|
124
130
|
# conditions.
|
125
131
|
#
|
@@ -155,8 +161,6 @@ module RSpec::Rails
|
|
155
161
|
included do
|
156
162
|
subject { controller }
|
157
163
|
|
158
|
-
metadata[:type] = :controller
|
159
|
-
|
160
164
|
before do
|
161
165
|
self.routes = ::Rails.application.routes
|
162
166
|
end
|