Method: Spec::DSL::Main#share_as

Defined in:
lib/spec/dsl/main.rb

#share_as(name, &block) ⇒ Object

Creates a Shared Example Group and assigns it to a constant

share_as :AllEditions do
  it "should do all editions stuff" ...
end

describe SmallEdition do
  it_should_behave_like AllEditions

  it "should do small edition stuff" do
    ...
  end
end

And, for those of you who prefer to use something more like Ruby, you can just include the module directly

describe SmallEdition do
  include AllEditions

  it "should do small edition stuff" do
    ...
  end
end
[View source]

78
79
80
81
82
83
84
85
86
87
88
# File 'lib/spec/dsl/main.rb', line 78

def share_as(name, &block)
  Spec.deprecate("share_as","shared_examples_for")
  begin
    args = [name]
    add_options(args)
    set_location(args.options, caller(0)[1])
    Object.const_set(name, Spec::Example::ExampleGroupFactory.create_shared_example_group(*args, &block))
  rescue NameError => e
    raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
  end
end