Skip to content

Instantly share code, notes, and snippets.

@justinko
Created March 22, 2011 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save justinko/880921 to your computer and use it in GitHub Desktop.
Save justinko/880921 to your computer and use it in GitHub Desktop.
# Replaces `for_groups_matching`
RSpec.configure do |config|
config.shared :type => :model do
let(:foo) { 'only in models' }
end
end
# I'm actually against being able to call `shared`
# on the configuration instance. It's just not needed.
# You could achieve the same by doing this:
# In support/model_configuration.rb
shared :type => :model do
let(:foo) { 'only in models' }
end
# -------------------------------------
# Replaces `shared_examples_for`
# In support/slug_examples.rb
shared 'a model with a slug' do
it 'sets the slug column upon initialization' do
described_class.new.slug.should_not be_blank
end
end
# In post_spec.rb
describe Post do
it_should_behave_like 'a model with a slug'
end
# -------------------------------------
# Replaces `SharedContext`
# In support/user_setup.rb
shared 'basic user' do
let(:user) { Factory(:user) }
before { user.set_initial_password }
end
# In user_spec.rb
describe User do
context 'that is suspended' do
with_shared_context 'basic user'
before { user.suspend! }
it 'does not receive email' do
user.receive_email?.should be_false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment