Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Last active January 2, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonRowe/f19eb6f69692f90a1b26 to your computer and use it in GitHub Desktop.
Save JonRowe/f19eb6f69692f90a1b26 to your computer and use it in GitHub Desktop.
describe do
module Global
class << self
attr_accessor :shared_state
end
end
shared_examples_for "example" do |value|
puts "Defining state: #{Global.shared_state = value}"
specify do
puts "Using state #{Global.shared_state}"
expect(Global.shared_state).to eq value
end
end
it_should_behave_like "example", :my_value
it_should_behave_like "example", :other_value
end
Defining state: my_value
Defining state: other_value
Using state other_value
Using state other_value
F.
Failures:
1) it should behave like example should eq :my_value
Failure/Error: expect(Global.shared_state).to eq value
expected: :my_value
got: :other_value
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-:my_value
+:other_value
Shared Example Group: "example" called from ./examples_spec.rb:17
# ./examples_spec.rb:13:in `block (3 levels) in <top (required)>'
Finished in 0.00108 seconds
2 examples, 1 failure
Failed examples:
rspec ./examples_spec.rb:11 # it should behave like example should eq :my_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment