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.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -1
  4. data/Capybara.md +1 -3
  5. data/Changelog.md +126 -58
  6. data/README.md +31 -4
  7. data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
  8. data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
  9. data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
  10. data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
  11. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
  12. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  13. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
  14. data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
  15. data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
  16. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
  17. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
  18. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  19. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
  20. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
  21. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  22. data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
  23. data/lib/rspec/rails.rb +1 -8
  24. data/lib/rspec/rails/configuration.rb +72 -0
  25. data/lib/rspec/rails/example.rb +0 -64
  26. data/lib/rspec/rails/example/controller_example_group.rb +16 -12
  27. data/lib/rspec/rails/example/feature_example_group.rb +0 -2
  28. data/lib/rspec/rails/example/helper_example_group.rb +0 -2
  29. data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
  30. data/lib/rspec/rails/example/model_example_group.rb +0 -4
  31. data/lib/rspec/rails/example/request_example_group.rb +0 -2
  32. data/lib/rspec/rails/example/routing_example_group.rb +0 -2
  33. data/lib/rspec/rails/example/view_example_group.rb +1 -2
  34. data/lib/rspec/rails/extensions.rb +0 -1
  35. data/lib/rspec/rails/fixture_support.rb +0 -8
  36. data/lib/rspec/rails/matchers.rb +1 -0
  37. data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
  38. data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
  39. data/lib/rspec/rails/tasks/rspec.rake +12 -5
  40. data/lib/rspec/rails/version.rb +1 -1
  41. data/lib/rspec/rails/view_rendering.rb +6 -34
  42. metadata +42 -316
  43. metadata.gz.sig +0 -0
  44. data/features/Generators.md +0 -25
  45. data/features/GettingStarted.md +0 -84
  46. data/features/README.md +0 -48
  47. data/features/RailsVersions.md +0 -4
  48. data/features/Transactions.md +0 -84
  49. data/features/Upgrade.md +0 -121
  50. data/features/controller_specs/Cookies.md +0 -57
  51. data/features/controller_specs/README.md +0 -45
  52. data/features/controller_specs/anonymous_controller.feature +0 -436
  53. data/features/controller_specs/bypass_rescue.feature +0 -75
  54. data/features/controller_specs/controller_spec.feature +0 -58
  55. data/features/controller_specs/engine_routes.feature +0 -51
  56. data/features/controller_specs/isolation_from_views.feature +0 -87
  57. data/features/controller_specs/render_views.feature +0 -114
  58. data/features/directory_structure.feature +0 -71
  59. data/features/feature_specs/feature_spec.feature +0 -35
  60. data/features/helper_specs/helper_spec.feature +0 -122
  61. data/features/mailer_specs/url_helpers.feature +0 -38
  62. data/features/matchers/README.md +0 -18
  63. data/features/matchers/new_record_matcher.feature +0 -41
  64. data/features/matchers/redirect_to_matcher.feature +0 -40
  65. data/features/matchers/relation_match_array.feature +0 -27
  66. data/features/matchers/render_template_matcher.feature +0 -49
  67. data/features/mocks/mock_model.feature +0 -147
  68. data/features/mocks/stub_model.feature +0 -58
  69. data/features/model_specs/README.md +0 -21
  70. data/features/model_specs/errors_on.feature +0 -51
  71. data/features/model_specs/records.feature +0 -27
  72. data/features/model_specs/transactional_examples.feature +0 -109
  73. data/features/request_specs/request_spec.feature +0 -49
  74. data/features/routing_specs/README.md +0 -16
  75. data/features/routing_specs/be_routable_matcher.feature +0 -80
  76. data/features/routing_specs/engine_routes.feature +0 -38
  77. data/features/routing_specs/named_routes.feature +0 -18
  78. data/features/routing_specs/route_to_matcher.feature +0 -90
  79. data/features/step_definitions/additional_cli_steps.rb +0 -4
  80. data/features/step_definitions/model_steps.rb +0 -3
  81. data/features/support/capybara.rb +0 -7
  82. data/features/support/env.rb +0 -53
  83. data/features/support/rails_versions.rb +0 -4
  84. data/features/support/rubinius.rb +0 -6
  85. data/features/view_specs/inferred_controller_path.feature +0 -45
  86. data/features/view_specs/stub_template.feature +0 -51
  87. data/features/view_specs/view_spec.feature +0 -206
  88. data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
  89. data/lib/rspec/rails/mocks.rb +0 -272
  90. data/lib/rspec/rails/vendor/webrat.rb +0 -33
  91. data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
  92. data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
  93. data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
  94. data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
  95. data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
  96. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
  97. data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
  98. data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
  99. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
  100. data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
  101. data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
  102. data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
  103. data/spec/rspec/rails/configuration_spec.rb +0 -26
  104. data/spec/rspec/rails/deprecations_spec.rb +0 -18
  105. data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
  106. data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
  107. data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
  108. data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
  109. data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
  110. data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
  111. data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
  112. data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
  113. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
  114. data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
  115. data/spec/rspec/rails/fixture_support_spec.rb +0 -17
  116. data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
  117. data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
  118. data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
  119. data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
  120. data/spec/rspec/rails/matchers/has_spec.rb +0 -29
  121. data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
  122. data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
  123. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
  124. data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
  125. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
  126. data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
  127. data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
  128. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
  129. data/spec/rspec/rails/view_rendering_spec.rb +0 -111
  130. data/spec/spec_helper.rb +0 -33
  131. data/spec/support/ar_classes.rb +0 -42
  132. data/spec/support/helpers.rb +0 -34
  133. data/spec/support/matchers.rb +0 -9
  134. data/spec/support/null_object.rb +0 -6
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
- describe <%= class_name %>Controller do
4
+ describe <%= class_name %>Controller, :type => :controller do
5
5
 
6
6
  <% for action in actions -%>
7
7
  describe "GET '<%= action %>'" do
@@ -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
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- feature "<%= class_name.pluralize %>" do
3
+ feature "<%= class_name.pluralize %>", :type => :feature do
4
4
  pending "add some scenarios (or delete) #{__FILE__}"
5
5
  end
@@ -11,7 +11,7 @@ require 'spec_helper'
11
11
  # end
12
12
  # end
13
13
  <% module_namespacing do -%>
14
- describe <%= class_name %>Helper do
14
+ describe <%= class_name %>Helper, :type => :helper do
15
15
  pending "add some examples to (or delete) #{__FILE__}"
16
16
  end
17
17
  <% 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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "<%= class_name.pluralize %>" do
3
+ describe "<%= class_name.pluralize %>", :type => :request do
4
4
  describe "GET /<%= table_name %>" do
5
5
  it "works! (now write some real specs)" do
6
6
  get <%= index_helper %>_path
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- describe <%= class_name %> do
4
+ describe <%= class_name %>, :type => :mailer do
5
5
  <% for action in actions -%>
6
6
  describe "<%= action %>" do
7
7
  let(:mail) { <%= class_name %>.<%= action %> }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
- describe <%= class_name %> do
4
+ describe <%= class_name %>, :type => :model do
5
5
  pending "add some examples to (or delete) #{__FILE__}"
6
6
  end
7
7
  <% end -%>
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
- describe <%= class_name %>Observer do
4
+ describe <%= class_name %>Observer, :type => :observer do
5
5
  pending "add some examples to (or delete) #{__FILE__}"
6
6
  end
7
7
  <% 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
- allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
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
- allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
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 %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
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
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>[name=?]", "<%= ns_file_name %>[<%= attribute.name %>]"
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
- stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
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 %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
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? ? " ).as_new_record)\n end" : " end" %>
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
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>[name=?]", "<%= ns_file_name %>[<%= attribute.name %>]"
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,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- describe <%= controller_class_name %>Controller do
4
+ describe <%= controller_class_name %>Controller, :type => :routing do
5
5
  describe "routing" do
6
6
 
7
7
  <% unless options[:singleton] -%>
@@ -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 %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
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 -%>
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "<%= file_path %>/<%= @action %>" do
3
+ describe "<%= file_path %>/<%= @action %>", :type => :view do
4
4
  pending "add some examples to (or delete) #{__FILE__}"
5
5
  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
@@ -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
- metadata[:example_group][:described_class] = Class.new(base_class) do
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
- metadata[:example_group][:described_class].class_eval(&body)
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
- self.routes = ActionDispatch::Routing::RouteSet.new.tap { |r|
80
- r.draw { resources resource_name }
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. Use this to
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