Sha256: 3079303118bae63635d8215a1e19271c864e684ee9ac984585e9be2d5bc3ec86

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

module RSpec::Core

  describe Subject do

    describe "implicit subject" do
      describe "with a class" do
        it "returns an instance of the class" do
          ExampleGroup.describe(Array).subject.call.should == []
        end
      end
      
      describe "with a Module" do
        it "returns the Module" do
          ExampleGroup.describe(Enumerable).subject.call.should == Enumerable
        end
      end
      
      describe "with a string" do
        it "return the string" do
          ExampleGroup.describe("Foo").subject.call.should == 'Foo'
        end
      end

      describe "with a number" do
        it "returns the number" do
          ExampleGroup.describe(15).subject.call.should == 15
        end
      end
      
    end
    
    describe "explicit subject" do
      describe "defined in a top level group" do
        it "replaces the implicit subject in that group" do
          group = ExampleGroup.describe(Array)
          group.subject { [1,2,3] }
          group.subject.call.should == [1,2,3]
        end
      end

      describe "defined in a top level group" do
        let(:group) do
          ExampleGroup.describe do
            subject{ [4,5,6] }
          end
        end

        it "is available in a nested group (subclass)" do
          nested_group = group.describe("I'm nested!") { }
          nested_group.subject.call.should == [4,5,6]
        end

        it "is available in a doubly nested group (subclass)" do
          nested_group = group.describe("Nesting level 1") { }
          doubly_nested_group = nested_group.describe("Nesting level 2") { }
          doubly_nested_group.subject.call.should == [4,5,6]
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rspec-core-2.0.0.beta.17 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.16 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.15 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.14 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.13 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.12 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.11 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.10 spec/rspec/core/subject_spec.rb
rspec-core-2.0.0.beta.9 spec/rspec/core/subject_spec.rb