Skip to content

Instantly share code, notes, and snippets.

@rf-
Created October 4, 2012 04:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rf-/3831565 to your computer and use it in GitHub Desktop.
Save rf-/3831565 to your computer and use it in GitHub Desktop.
require 'rspec/autorun'
module Stuff
def authenticated_as
puts "1: #{self.inspect}"
context 'when there is stuff' do
puts "2: #{self.inspect}"
yield
end
end
end
RSpec.configure do |config|
config.extend Stuff
end
describe "some stuff" do
puts "0: #{self.inspect}"
authenticated_as do
puts "3: #{self.inspect}"
it "should work" do
true.should be_false
end
end
end
# output:
# src/tmp/rspec $ ruby test.rb
# 0: #<Class:0x007f9985b50150>
# 1: #<Class:0x007f9985b50150>
# 2: #<Class:0x007f9985b478c0>
# 3: #<Class:0x007f9985b50150>
require 'rspec/autorun'
module Stuff
def authenticated_as(&blk)
puts "1: #{self.inspect}"
context 'when there is stuff' do
puts "2: #{self.inspect}"
instance_eval(&blk)
end
end
end
RSpec.configure do |config|
config.extend Stuff
end
describe "some stuff" do
puts "0: #{self.inspect}"
authenticated_as do
puts "3: #{self.inspect}"
it "should work" do
true.should be_false
end
end
end
# output:
# src/tmp/rspec $ ruby test.rb
# 0: #<Class:0x007ff006350130>
# 1: #<Class:0x007ff006350130>
# 2: #<Class:0x007ff006347fa8>
# 3: #<Class:0x007ff006347fa8>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment