Method: Context::TestCase::ClassMethods#shared
- Defined in:
- lib/context/shared_behavior.rb
#shared(name, &block) ⇒ Object
Share behavior among different contexts. This creates a module (actually, a Module subclass) that is included using the use method (or one of its aliases) provided by context or include if you know the module’s constant name.
Examples
shared "other things" do
it "should do things but not some things" do
# behavior is fun
end
end
use "other things"
# or...
it_should_behave_like "other things"
shared :client do
it "should be a client to our server" do
# TODO: client behavior here
end
end
use :client
# or...
uses "client"
behaves_like "client"
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/context/shared_behavior.rb', line 48 def shared(name, &block) case name.class.name when "String" name = name.to_module_name when "Symbol" name = name.to_s.to_module_name else raise ArgumentError, "Provide a String or Symbol as the name of the shared behavior group" end Object.const_set(name, Context::SharedBehavior.create_from_behavior(block)) end |