Skip to content

Commit ba3db74

Browse files
committed
Turn on partial double verification in specs
1 parent 93f8423 commit ba3db74

File tree

7 files changed

+54
-39
lines changed

7 files changed

+54
-39
lines changed

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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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/helper_example_group_spec.rb

Lines changed: 8 additions & 6 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

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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::ExampleGroup.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/matchers/have_rendered_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
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
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
RSpec.describe RSpec::Rails::SetupAndTeardownAdapter do
2-
describe "::setup" do
2+
describe ".setup" do
33
it "registers before hooks in the order setup is received" do
4-
klass = Class.new do
4+
group = RSpec::Core::ExampleGroup.describe do
55
include RSpec::Rails::SetupAndTeardownAdapter
66
def self.foo; "foo"; end
77
def self.bar; "bar"; end
88
end
9-
expect(klass).to receive(:before).ordered { |&block| expect(block.call).to eq "foo" }
10-
expect(klass).to receive(:before).ordered { |&block| expect(block.call).to eq "bar" }
11-
expect(klass).to receive(:before).ordered { |&block| expect(block.call).to eq "baz" }
9+
expect(group).to receive(:before).ordered { |&block| expect(block.call).to eq "foo" }
10+
expect(group).to receive(:before).ordered { |&block| expect(block.call).to eq "bar" }
11+
expect(group).to receive(:before).ordered { |&block| expect(block.call).to eq "baz" }
1212

13-
klass.setup :foo
14-
klass.setup :bar
15-
klass.setup { "baz" }
13+
group.setup :foo
14+
group.setup :bar
15+
group.setup { "baz" }
1616
end
1717

1818
it "registers prepend_before hooks for the Rails' setup methods" do
19-
klass = Class.new do
19+
group = RSpec::Core::ExampleGroup.describe do
2020
include RSpec::Rails::SetupAndTeardownAdapter
2121
def self.setup_fixtures; "setup fixtures" end
2222
def self.setup_controller_request_and_response; "setup controller" end
2323
end
2424

25-
expect(klass).to receive(:prepend_before) { |&block| expect(block.call).to eq "setup fixtures" }
26-
expect(klass).to receive(:prepend_before) { |&block| expect(block.call).to eq "setup controller" }
25+
expect(group).to receive(:prepend_before) { |&block| expect(block.call).to eq "setup fixtures" }
26+
expect(group).to receive(:prepend_before) { |&block| expect(block.call).to eq "setup controller" }
2727

28-
klass.setup :setup_fixtures
29-
klass.setup :setup_controller_request_and_response
28+
group.setup :setup_fixtures
29+
group.setup :setup_controller_request_and_response
3030
end
3131

3232
it "registers teardown hooks in the order setup is received" do
33-
klass = Class.new do
33+
group = RSpec::Core::ExampleGroup.describe do
3434
include RSpec::Rails::SetupAndTeardownAdapter
3535
def self.foo; "foo"; end
3636
def self.bar; "bar"; end
3737
end
38-
expect(klass).to receive(:after).ordered { |&block| expect(block.call).to eq "foo" }
39-
expect(klass).to receive(:after).ordered { |&block| expect(block.call).to eq "bar" }
40-
expect(klass).to receive(:after).ordered { |&block| expect(block.call).to eq "baz" }
38+
expect(group).to receive(:after).ordered { |&block| expect(block.call).to eq "foo" }
39+
expect(group).to receive(:after).ordered { |&block| expect(block.call).to eq "bar" }
40+
expect(group).to receive(:after).ordered { |&block| expect(block.call).to eq "baz" }
4141

42-
klass.teardown :foo
43-
klass.teardown :bar
44-
klass.teardown { "baz" }
42+
group.teardown :foo
43+
group.teardown :bar
44+
group.teardown { "baz" }
4545
end
4646
end
4747
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def self.run_all(reporter=nil)
3333
end
3434

3535
config.mock_with :rspec do |mocks|
36-
# mocks.verify_partial_doubles = true
36+
mocks.verify_partial_doubles = true
3737
mocks.verify_doubled_constant_names = true
3838
end
3939

0 commit comments

Comments
 (0)