Skip to content

Commit e23efbb

Browse files
authored
Merge pull request #2264 from rspec/update-spec_helper-to-use-defaults
Streamline RSpec config
2 parents b1ffe94 + ba3db74 commit e23efbb

27 files changed

+100
-67
lines changed

spec/rspec/rails/assertion_adapter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe RSpec::Rails::MinitestAssertionAdapter do
1+
RSpec.describe RSpec::Rails::MinitestAssertionAdapter do
22
include RSpec::Rails::MinitestAssertionAdapter
33

44
RSpec::Rails::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk|refute)/}.each do |m|

spec/rspec/rails/assertion_delegator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe RSpec::Rails::AssertionDelegator do
1+
RSpec.describe RSpec::Rails::AssertionDelegator do
22
it "provides a module that delegates assertion methods to an isolated class" do
33
klass = Class.new {
44
include RSpec::Rails::AssertionDelegator.new(RSpec::Rails::Assertions)

spec/rspec/rails/configuration_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def in_inferring_type_from_location_environment
196196
it "metadata `type: :request` sets up request example groups" do
197197
a_rails_app = double("Rails application")
198198
the_rails_module = Module.new {
199-
def self.version; end;
199+
def self.version; end
200+
def self.application; end
200201
}
201202
allow(the_rails_module).to receive(:application) { a_rails_app }
202203
version = ::Rails::VERSION
@@ -232,7 +233,8 @@ def self.version; end;
232233
it "metadata `type: :feature` sets up feature example groups" do
233234
a_rails_app = double("Rails application")
234235
the_rails_module = Module.new {
235-
def self.version; end;
236+
def self.version; end
237+
def self.application; end
236238
}
237239
allow(the_rails_module).to receive(:application) { a_rails_app }
238240
version = ::Rails::VERSION

spec/rspec/rails/example/controller_example_group_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def self.abstract?; false; end
33
end
44

55
module RSpec::Rails
6-
describe ControllerExampleGroup do
6+
RSpec.describe ControllerExampleGroup do
77
it_behaves_like "an rspec-rails example group mixin", :controller,
88
'./spec/controllers/', '.\\spec\\controllers\\'
99

@@ -60,12 +60,11 @@ def my_helper
6060
let(:controller) { double('controller') }
6161
let(:example) { group.new }
6262
let(:routes) do
63-
routes = nil
6463
with_isolated_stderr do
6564
routes = ActionDispatch::Routing::RouteSet.new
6665
routes.draw { resources :foos }
66+
routes
6767
end
68-
routes
6968
end
7069

7170
before do
@@ -84,7 +83,6 @@ def my_helper
8483

8584
it "calls NamedRouteCollection#route_defined? when it checks that given route is defined or not" do
8685
expect(routes.named_routes).to receive(:route_defined?).and_return(true)
87-
expect(routes.named_routes).not_to receive(:helpers)
8886

8987
example.foos_url
9088
end

spec/rspec/rails/example/feature_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe FeatureExampleGroup do
2+
RSpec.describe FeatureExampleGroup do
33
it_behaves_like "an rspec-rails example group mixin", :feature,
44
'./spec/features/', '.\\spec\\features\\'
55

spec/rspec/rails/example/helper_example_group_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class InternalClass
2020

2121
describe "#helper" do
2222
it "returns the instance of AV::Base provided by AV::TC::Behavior" do
23-
helper_spec = Object.new.extend HelperExampleGroup
24-
expect(helper_spec).to receive(:view_assigns)
25-
av_tc_b_view = double('_view')
26-
expect(av_tc_b_view).to receive(:assign)
27-
allow(helper_spec).to receive(:_view) { av_tc_b_view }
28-
expect(helper_spec.helper).to eq(av_tc_b_view)
23+
without_partial_double_verification do
24+
helper_spec = Object.new.extend HelperExampleGroup
25+
expect(helper_spec).to receive(:view_assigns)
26+
av_tc_b_view = double('_view')
27+
expect(av_tc_b_view).to receive(:assign)
28+
allow(helper_spec).to receive(:_view) { av_tc_b_view }
29+
expect(helper_spec.helper).to eq(av_tc_b_view)
30+
end
2931
end
3032

3133
before do
@@ -54,7 +56,7 @@ def _view
5456
end
5557
end
5658

57-
describe HelperExampleGroup::ClassMethods do
59+
RSpec.describe HelperExampleGroup::ClassMethods do
5860
describe "determine_default_helper_class" do
5961
let(:group) do
6062
RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/job_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe JobExampleGroup do
2+
RSpec.describe JobExampleGroup do
33
if defined?(ActiveJob)
44
it_behaves_like "an rspec-rails example group mixin", :job,
55
'./spec/jobs/', '.\\spec\\jobs\\'

spec/rspec/rails/example/mailer_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe MailerExampleGroup do
2+
RSpec.describe MailerExampleGroup do
33
module ::Rails; end
44
before do
55
allow(Rails).to receive_message_chain(:application, :routes, :url_helpers).and_return(Rails)

spec/rspec/rails/example/model_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe ModelExampleGroup do
2+
RSpec.describe ModelExampleGroup do
33
it_behaves_like "an rspec-rails example group mixin", :model,
44
'./spec/models/', '.\\spec\\models\\'
55
end

spec/rspec/rails/example/request_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe RequestExampleGroup do
2+
RSpec.describe RequestExampleGroup do
33
it_behaves_like "an rspec-rails example group mixin", :request,
44
'./spec/requests/', '.\\spec\\requests\\',
55
'./spec/integration/', '.\\spec\\integration\\',

spec/rspec/rails/example/routing_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe RoutingExampleGroup do
2+
RSpec.describe RoutingExampleGroup do
33
it_behaves_like "an rspec-rails example group mixin", :routing,
44
'./spec/routing/', '.\\spec\\routing\\'
55

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe ViewExampleGroup do
2+
RSpec.describe ViewExampleGroup do
33
it_behaves_like "an rspec-rails example group mixin", :view,
44
'./spec/views/', '.\\spec\\views\\'
55

@@ -8,15 +8,19 @@ module ::ThingsHelper; end
88
module ::Namespaced; module ThingsHelper; end; end
99

1010
it 'includes the helper with the same name' do
11-
group = RSpec::Core::ExampleGroup.describe 'things/show.html.erb'
11+
group = RSpec::Core::ExampleGroup.describe('things/show.html.erb') do
12+
def self.helper(*); end # Stub method
13+
end
1214
expect(group).to receive(:helper).with(ThingsHelper)
1315
group.class_exec do
1416
include ViewExampleGroup
1517
end
1618
end
1719

1820
it 'includes the namespaced helper with the same name' do
19-
group = RSpec::Core::ExampleGroup.describe 'namespaced/things/show.html.erb'
21+
group = RSpec::Core::ExampleGroup.describe('namespaced/things/show.html.erb') do
22+
def self.helper(*); end # Stub method
23+
end
2024
expect(group).to receive(:helper).with(Namespaced::ThingsHelper)
2125
group.class_exec do
2226
include ViewExampleGroup
@@ -56,7 +60,9 @@ module ::ApplicationHelper; end
5660
end
5761

5862
it 'includes the application helper' do
59-
group = RSpec::Core::Example.describe 'bars/new.html.erb'
63+
group = RSpec::Core::ExampleGroup.describe('bars/new.html.erb') do
64+
def self.helper(*); end # Stub method
65+
end
6066
expect(group).to receive(:helper).with(ApplicationHelper)
6167
group.class_exec do
6268
include ViewExampleGroup
@@ -124,6 +130,7 @@ def _assigns
124130
end
125131
end
126132
include local
133+
def _default_file_to_render; end # Stub method
127134
include ViewExampleGroup::ExampleMethods
128135
end.new
129136
end
@@ -174,7 +181,7 @@ def _assigns
174181
Class.new do
175182
include ViewExampleGroup::ExampleMethods
176183
def controller
177-
@controller ||= Object.new
184+
@controller ||= OpenStruct.new(params: nil)
178185
end
179186
end.new
180187
end
@@ -189,8 +196,10 @@ def controller
189196
let(:view_spec) do
190197
Class.new do
191198
include ViewExampleGroup::ExampleMethods
199+
def _default_file_to_render; end
192200
end.new
193201
end
202+
194203
context "with a common _default_file_to_render" do
195204
it "it returns the directory" do
196205
allow(view_spec).to receive(:_default_file_to_render).
@@ -213,6 +222,7 @@ def controller
213222
describe "#view" do
214223
let(:view_spec) do
215224
Class.new do
225+
def _view; end # Stub method
216226
include ViewExampleGroup::ExampleMethods
217227
end.new
218228
end
@@ -227,13 +237,13 @@ def controller
227237
with_isolated_config do
228238
run_count = 0
229239
RSpec.configuration.before(:each, :type => :view) do
230-
allow(view).to receive(:a_stubbed_helper) { :value }
240+
allow(view).to receive(:render) { :value }
231241
run_count += 1
232242
end
233243
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
234244
specify { true }
235245
end
236-
group.run NullObject.new
246+
group.run
237247
expect(run_count).to eq 1
238248
end
239249
end

spec/rspec/rails/fixture_file_upload_support_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe FixtureFileUploadSupport do
2+
RSpec.describe FixtureFileUploadSupport do
33
context 'with fixture path set in config' do
44
it 'resolves fixture file' do
55
RSpec.configuration.fixture_path = File.dirname(__FILE__)

spec/rspec/rails/fixture_support_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RSpec::Rails
2-
describe FixtureSupport do
2+
RSpec.describe FixtureSupport do
33
context "with use_transactional_fixtures set to false" do
44
it "still supports fixture_path" do
55
allow(RSpec.configuration).to receive(:use_transactional_fixtures) { false }

spec/rspec/rails/matchers/be_a_new_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe "be_a_new matcher" do
1+
RSpec.describe "be_a_new matcher" do
22
context "new record" do
33
let(:record) do
44
Class.new do

spec/rspec/rails/matchers/be_new_record_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe "be_new_record" do
1+
RSpec.describe "be_new_record" do
22
context "a new record" do
33
let(:record) { double('record', new_record?: true) }
44

spec/rspec/rails/matchers/be_routable_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe "be_routable" do
1+
RSpec.describe "be_routable" do
22
include RSpec::Rails::Matchers::RoutingMatchers
33
attr_reader :routes
44

spec/rspec/rails/matchers/be_valid_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'rspec/rails/matchers/be_valid'
22

3-
describe "be_valid matcher" do
3+
RSpec.describe "be_valid matcher" do
44
class Post
55
include ActiveModel::Validations
66
attr_accessor :title

spec/rspec/rails/matchers/has_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AssociatedItem < ActiveRecord::Base
1919
belongs_to :collection_owner
2020
end
2121

22-
describe "should have_xxx" do
22+
RSpec.describe "should have_xxx" do
2323
it "works with ActiveRecord::Associations::CollectionProxy" do
2424
owner = CollectionOwner.new
2525
expect(owner.associated_items).to have_some_quality

spec/rspec/rails/matchers/have_rendered_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
%w[have_rendered render_template].each do |template_expectation|
2-
describe template_expectation do
2+
RSpec.describe template_expectation do
33
include RSpec::Rails::Matchers::RenderTemplate
44
let(:response) { ActionDispatch::TestResponse.new }
55

66
context "given a hash" do
7+
def assert_template(*); end
78
it "delegates to assert_template" do
89
expect(self).to receive(:assert_template).with({:this => "hash"}, "this message")
910
expect("response").to send(template_expectation, {:this => "hash"}, "this message")
1011
end
1112
end
1213

1314
context "given a string" do
15+
def assert_template(*); end
1416
it "delegates to assert_template" do
1517
expect(self).to receive(:assert_template).with("this string", "this message")
1618
expect("response").to send(template_expectation, "this string", "this message")
1719
end
1820
end
1921

2022
context "given a symbol" do
23+
def assert_template(*); end
2124
it "converts to_s and delegates to assert_template" do
2225
expect(self).to receive(:assert_template).with("template_name", "this message")
2326
expect("response").to send(template_expectation, :template_name, "this message")
@@ -26,8 +29,8 @@
2629

2730
context "with should" do
2831
context "when assert_template passes" do
32+
def assert_template(*); end
2933
it "passes" do
30-
def assert_template(*); end
3134
expect do
3235
expect(response).to send(template_expectation, "template_name")
3336
end.to_not raise_exception

spec/rspec/rails/matchers/redirect_to_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "active_support"
22
require "active_support/test_case"
33

4-
describe "redirect_to" do
4+
RSpec.describe "redirect_to" do
55
include RSpec::Rails::Matchers::RedirectTo
66

77
let(:response) { ActionDispatch::TestResponse.new }

spec/rspec/rails/matchers/relation_match_array_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe "ActiveSupport::Relation match_array matcher" do
1+
RSpec.describe "ActiveSupport::Relation match_array matcher" do
22
before { MockableModel.delete_all }
33

44
let!(:models) { Array.new(3) { MockableModel.create } }

spec/rspec/rails/matchers/route_to_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe "route_to" do
1+
RSpec.describe "route_to" do
22
include RSpec::Rails::Matchers::RoutingMatchers
33
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
44

spec/rspec/rails/minitest_lifecycle_adapter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe RSpec::Rails::MinitestLifecycleAdapter do
1+
RSpec.describe RSpec::Rails::MinitestLifecycleAdapter do
22
it "invokes minitest lifecycle hooks at the appropriate times" do
33
invocations = []
44
example_group = RSpec::Core::ExampleGroup.describe("MinitestHooks") do

0 commit comments

Comments
 (0)