Created
January 14, 2015 12:04
-
-
Save mikekreeki/8dae4506be130cd82dc4 to your computer and use it in GitHub Desktop.
Action macro for RSpec (very useful for controller specs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpec | |
module Macros | |
def action(&block) | |
before do |example| | |
if example.metadata.fetch(:action, true) | |
instance_eval(&block) | |
end | |
end | |
end | |
end | |
end | |
RSpec.configure do |config| | |
config.extend RSpec::Macros | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
action do | |
post :create | |
end | |
it 'does something' do | |
# action will be triggered before | |
end | |
it 'does something', action: false do | |
# action won't be triggered before | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment