-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Streamline RSpec config #2264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streamline RSpec config #2264
Conversation
spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb
Outdated
Show resolved
Hide resolved
ed5824f
to
43bb489
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JonRowe please take another look. Enabled partial double verification.
@@ -225,6 +235,7 @@ def controller | |||
|
|||
it 'is accessible to hooks' do | |||
with_isolated_config do | |||
view = double("view") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea why it was passing before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is view
not also a method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope nor these links
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_isolated_config
does not swallow errors, it just runs an ensure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's defined here: lib/rspec/rails/example/view_example_group.rb:81
so this should be removed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point.
When I comment out with_isolated_config
and locally defined view
double, the hook is not executed. It is not executed with with_isolated_config
or if metadata condition is removed.
The following doesn't work either:
context 'with a hook' do
let(:run_count) { [] }
before(:each, :type => :view) do
allow(view).to receive(:a_stubbed_helper) { :value }
run_count << 1
end
it 'is accessible to hooks' do
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
specify { true }
end
group.run NullObject.new
expect(run_count.first).to eq 1
end
end
Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to keep with_isolated_config
, if your changes here are causing an error you need to ensure the right methods are defined, doing double
here is just wrong..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A call to allow(view).to receive(:a_stubbed_helper) { :value }
results in:
RSpec::Mocks::MockExpectationError: #<#<Class:0x00007fa59165da18>:0x00007fa59165ceb0 @_config={}, ...> does not implement: a_stubbed_helper
that for some reason doesn't bubble up.
The same happens if you move stubbing directly to the example:
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
specify {
allow(view).to receive(:a_stubbed_helper) { :value }
run_count += 1
}
end
Example returns prematurely, run_count
is not incremented, but there's no exception from mocks. Is it a bug?
Changed to stub an existing render
method instead.
Removed NullObject.new
from group.run
's arguments, it doesn't seem to affect this in any way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, a few questions mostly out of curiosity.
@@ -225,6 +235,7 @@ def controller | |||
|
|||
it 'is accessible to hooks' do | |||
with_isolated_config do | |||
view = double("view") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is view
not also a method?
@@ -225,6 +235,7 @@ def controller | |||
|
|||
it 'is accessible to hooks' do | |||
with_isolated_config do | |||
view = double("view") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's defined here: lib/rspec/rails/example/view_example_group.rb:81
so this should be removed...
@@ -225,6 +235,7 @@ def controller | |||
|
|||
it 'is accessible to hooks' do | |||
with_isolated_config do | |||
view = double("view") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point.
When I comment out with_isolated_config
and locally defined view
double, the hook is not executed. It is not executed with with_isolated_config
or if metadata condition is removed.
The following doesn't work either:
context 'with a hook' do
let(:run_count) { [] }
before(:each, :type => :view) do
allow(view).to receive(:a_stubbed_helper) { :value }
run_count << 1
end
it 'is accessible to hooks' do
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
specify { true }
end
group.run NullObject.new
expect(run_count.first).to eq 1
end
end
Any suggestions?
87b77ab
to
47893b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from figuring out the double issue this looks almost good to go, I think theres a bad rebase gone on though...
07afbbc
to
ba3db74
Compare
Rebase fixed, all green. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good but I spotted one last thing!
run_count += 1 | ||
end | ||
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do | ||
specify { true } | ||
end | ||
group.run NullObject.new | ||
group.run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this cause the groups output to be output to the real formatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no difference in the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised by that assertion, as the point of this object is to prevent the real reporter being used, but its failing locally for me? I want to investigate this further as its not possible to prove either way on CI without changing the format...
What I expect this to do is to add the spec you've specified above into the reporter, so if you run this spec on its own you'd see "2 examples passed" for this one example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I run it focused (rspec spec/rspec/rails/example/view_example_group_spec.rb:236
), it fails locally. However, the spec when run altogether passes.
This weird behavior remains even with just one example left, and if you remove module
namespace, and with_isolated_
, and nesting contexts. I've put it on my list to investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it doesn't add to the main reporter because of https://github.com/rspec/rspec-rails/pull/2264/files#diff-93830fa29d616f7c87903d08b5b1b29aR55 ?
config.around(:example) do |example|
real_world = RSpec.world
RSpec.instance_variable_set(:@world, RSpec::Core::World.new)
example.run
RSpec.instance_variable_set(:@world, real_world)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if with_isolated_config
is even necessary in specs with that hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I got to the bottom of why this doesn't run when focused. If you're interested its an artefact in our filtering, with_isolated_config
does not remove filters from this spec, as they exist in the world and the world is not isolated. That is something I might consider fixing at some point but is waaaaaaaaay out of scope for this.
I also confirmed this removal is ok, we now use a NullReporter
by default, a change which post-dates this spec I suspect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
run_count += 1 | ||
end | ||
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do | ||
specify { true } | ||
end | ||
group.run NullObject.new | ||
group.run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I got to the bottom of why this doesn't run when focused. If you're interested its an artefact in our filtering, with_isolated_config
does not remove filters from this spec, as they exist in the world and the world is not isolated. That is something I might consider fixing at some point but is waaaaaaaaay out of scope for this.
I also confirmed this removal is ok, we now use a NullReporter
by default, a change which post-dates this spec I suspect.
Disable monkey patching and fix specs related to this.