-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Run before(:all) hooks for rails magic example groups #829
Changes from 4 commits
f3b61ee
a49fb93
797224f
f7d8994
d125b6f
e8475dc
e2493d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require "spec_helper" | ||
|
||
class ::ApplicationController | ||
class ::ApplicationController < ActionController::Base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I run the group of specs to check that they work and the hooks are invoked. Controller specs require an actual controller to work. (And the build's still failing) |
||
end | ||
|
||
module RSpec::Rails | ||
|
@@ -96,5 +96,7 @@ module RSpec::Rails | |
controller_class.superclass.should eq(ApplicationController) | ||
end | ||
end | ||
|
||
it_behaves_like "runs metadata hooks of :type =>", :controller, ControllerExampleGroup | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,11 @@ def metadata_with(additional_metadata) | |
m | ||
end | ||
|
||
def with_isolated_config | ||
config = RSpec.configuration | ||
yield config.dup if block_given? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, it's not clear to me how this even works: you are yielding a dup of config, but it's not what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, good point, I need to set the config. I'm trying not to pollute the global config with my before hooks. |
||
RSpec.configuration = config | ||
end | ||
|
||
RSpec.configure {|c| c.include self} | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
shared_examples_for "runs metadata hooks of :type =>" do |type, type_group| | ||
|
||
[:before, :after].each do |hook| | ||
[:all, :each].each do |scope| | ||
|
||
it "runs #{hook} #{scope} hooks before groups of #{type}" do | ||
with_isolated_config do |config| | ||
run_count = 0 | ||
config.send(hook, scope, :type => type) { run_count += 1 } | ||
group = RSpec::Core::ExampleGroup.describe do | ||
include type_group | ||
specify { true } | ||
end | ||
group.run RSpec::Core::Reporter.new | ||
expect(run_count).to eq 1 | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
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.
Looks like this isn't used anywhere? Looks like a useful abstraction, though; if we stick with this solution for some reason it would be good to leverage this. (Although I suspect the final fix will be in rspec-core).
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.
Oops yeah, I tried to DRY it up (couldn't get it to work cause of the
included
scoping)