Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Created October 13, 2011 10:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kinopyo/1283896 to your computer and use it in GitHub Desktop.
Save kinopyo/1283896 to your computer and use it in GitHub Desktop.
rspec shared_context sample codes.
shared_context "shared stuff" do
before { @some_var = :some_value }
def shared_method
"it works"
end
let(:shared_let) { {'arbitrary' => 'object'} }
subject do
'this is the subject'
end
end
describe "group that includes a shared context using 'include_context'" do
include_context "shared stuff"
it "has access to methods defined in shared context" do
shared_method.should eq("it works")
end
it "has access to methods defined with let in shared context" do
shared_let['arbitrary'].should eq('object')
end
it "runs the before hooks defined in the shared context" do
@some_var.should be(:some_value)
end
it "accesses the subject defined in the shared context" do
subject.should eq('this is the subject')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment