Sha256: 841d6a30ae59b12b80d0df634f7a65f81386ca51d373afad381987b0d58083bd

Contents?: true

Size: 1.91 KB

Versions: 131

Compression:

Stored size: 1.91 KB

Contents

Feature: implicitly defined subject

  If the first argument to the outermost example group is a class, an instance
  of that class is exposed to each example via the `subject` method.

  While the examples below demonstrate how `subject` can be used as a
  user-facing concept, we recommend that you reserve it for support of custom
  matchers and/or extension libraries that hide its use from examples.
  
  Scenario: subject exposed in top level group
    Given a file named "top_level_subject_spec.rb" with:
      """
      describe Array do
        it "should be empty when first created" do
          subject.should be_empty
        end
      end
      """
    When I run `rspec ./top_level_subject_spec.rb`
    Then the examples should all pass

  Scenario: subject in a nested group
    Given a file named "nested_subject_spec.rb" with:
      """
      describe Array do
        describe "when first created" do
          it "should be empty" do
            subject.should be_empty
          end
        end
      end
      """
    When I run `rspec nested_subject_spec.rb`
    Then the examples should all pass

  Scenario: subject in a nested group with a different class (outermost wins)
    Given a file named "nested_subject_spec.rb" with:
      """
      class ArrayWithOneElement < Array
        def initialize(*)
          super
          unshift "first element"
        end
      end

      describe Array do
        describe ArrayWithOneElement do
          context "referenced as subject" do
            it "should be empty (because it is the Array declared at the top)" do
              subject.should be_empty
            end
          end

          context "created in the example" do
            it "should not be empty" do
              ArrayWithOneElement.new.should_not be_empty
            end
          end
        end
      end
      """
    When I run `rspec nested_subject_spec.rb`
    Then the examples should all pass

Version data entries

131 entries across 79 versions & 13 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/features/subject/implicit_subject.feature
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/features/subject/implicit_subject.feature
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.10.1/features/subject/implicit_subject.feature
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.9.0/features/subject/implicit_subject.feature
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature
classiccms-0.6.7 vendor/bundle/gems/rspec-core-2.10.0/features/subject/implicit_subject.feature