-
-
Save dchelimsky/1129417 to your computer and use it in GitHub Desktop.
using shared_context with a block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following is an example of how you might use shared content to reduce the | |
# duplication in https://gist.github.com/1128108. I prefer to avoid examples | |
# that use `should respond_to`, as it specifies structure rather than behavior. | |
# I'd recommend specifying something about what happens when the message is | |
# sent, e.g. subject.some_method.should eq(some_value). That implicitly | |
# specifies that the object responds to some_method, and provides more useful | |
# direction/information about how the object should behave. | |
# | |
# That said ... | |
RSpec.configure do |c| | |
c.alias_it_should_behave_like_to :can_be_extended_with, "extended with" | |
# ^^ use can_be_extended_with in a group and the output will say "extended | |
# with" | |
end | |
shared_examples MyModule do | |
before(:each){ subject.extend(MyModule) } | |
it { should respond_to(:some_method) } | |
end | |
describe Object do | |
extended_with MyModule | |
end | |
describe Class do | |
extended_with MyModule do | |
it { should respond_to(:special_method_for_class) } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object | |
extended with MyModule | |
should respond to #some_method | |
Class | |
extended with MyModule | |
should respond to #some_method | |
should respond to #special_method_for_class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment