Skip to content

Instantly share code, notes, and snippets.

@mikekreeki
Created January 14, 2015 12:04
Show Gist options
  • Save mikekreeki/8dae4506be130cd82dc4 to your computer and use it in GitHub Desktop.
Save mikekreeki/8dae4506be130cd82dc4 to your computer and use it in GitHub Desktop.
Action macro for RSpec (very useful for controller specs)
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
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