Sha256: a94def4f3a60f52470bf6f74fa55e77a8f8c68f74f1f4274aa6592eae3899ad1

Contents?: true

Size: 1.94 KB

Versions: 22

Compression:

Stored size: 1.94 KB

Contents

module SharedExampleGroupExample
  class OneThing
    def what_things_do
      "stuff"
    end
  end
  
  class AnotherThing
    def what_things_do
      "stuff"
    end
  end
  
  class YetAnotherThing
    def what_things_do
      "stuff"
    end
  end
  
  # A SharedExampleGroup is an example group that doesn't get run.
  # You can create one like this:
  share_examples_for "most things" do
    def helper_method
      "helper method"
    end
    
    it "should do what things do" do
      @thing.what_things_do.should == "stuff"
    end
  end

  # A SharedExampleGroup is also a module. If you create one like this it gets
  # assigned to the constant MostThings
  share_as :MostThings do
    def helper_method
      "helper method"
    end
    
    it "should do what things do" do
      @thing.what_things_do.should == "stuff"
    end
  end
  
  describe OneThing do
    # Now you can include the shared example group like this, which 
    # feels more like what you might say ...
    it_should_behave_like "most things"
    
    before(:each) { @thing = OneThing.new }
    
    it "should have access to helper methods defined in the shared example group" do
      helper_method.should == "helper method"
    end
  end

  describe AnotherThing do
    # ... or you can include the example group like this, which
    # feels more like the programming language we love.
    it_should_behave_like MostThings
    
    before(:each) { @thing = AnotherThing.new }

    it "should have access to helper methods defined in the shared example group" do
      helper_method.should == "helper method"
    end
  end

  describe YetAnotherThing do
    # ... or you can include the example group like this, which
    # feels more like the programming language we love.
    include MostThings
    
    before(:each) { @thing = AnotherThing.new }

    it "should have access to helper methods defined in the shared example group" do
      helper_method.should == "helper method"
    end
  end
end

Version data entries

22 entries across 22 versions & 8 rubygems

Version Path
rspec-1.3.0 examples/passing/shared_example_group_example.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/examples/passing/shared_example_group_example.rb
media-path-0.1.2 vendor/rspec/examples/passing/shared_example_group_example.rb
simple-templater-0.0.1.3 vendor/rspec/examples/passing/shared_example_group_example.rb
pupu-0.0.2.pre vendor/rspec/examples/passing/shared_example_group_example.rb
media-path-0.1.1.pre vendor/rspec/examples/passing/shared_example_group_example.rb
simple-templater-0.0.1.2 vendor/rspec/examples/passing/shared_example_group_example.rb
media-path-0.1.1 vendor/rspec/examples/passing/shared_example_group_example.rb
simple-templater-0.0.1.1 vendor/rspec/examples/passing/shared_example_group_example.rb
pupu-0.0.2 vendor/rspec/examples/passing/shared_example_group_example.rb
rango-0.0.6 vendor/rspec/examples/passing/shared_example_group_example.rb
rango-0.1.pre vendor/rspec/examples/passing/shared_example_group_example.rb
pupu-0.0.1 vendor/rspec/examples/passing/shared_example_group_example.rb
media-path-0.1 vendor/rspec/examples/passing/shared_example_group_example.rb
simple-templater-0.0.1 vendor/rspec/examples/passing/shared_example_group_example.rb
middleman-0.10.17 vendor/gems/gems/rspec-1.2.9/examples/passing/shared_example_group_example.rb
middleman-0.10.16 vendor/gems/gems/rspec-1.2.9/examples/passing/shared_example_group_example.rb
middleman-0.10.15 vendor/gems/gems/rspec-1.2.9/examples/passing/shared_example_group_example.rb
rackjour-0.1.8 vendor/gems/gems/rspec-1.2.9/examples/passing/shared_example_group_example.rb
middleman-0.10.14 vendor/gems/gems/rspec-1.2.9/examples/passing/shared_example_group_example.rb