Sha256: 045d95ee3f45179c0ead095cee68fa700cc977a10f399f58bfd1b325d03f74be

Contents?: true

Size: 1.92 KB

Versions: 38

Compression:

Stored size: 1.92 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:
      """ruby
      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:
      """ruby
      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:
      """ruby
      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

38 entries across 38 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-core-2.14.8/features/subject/implicit_subject.feature
rspec-core-2.99.2 features/subject/implicit_subject.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-core-2.14.7/features/subject/implicit_subject.feature
rspec-core-2.99.1 features/subject/implicit_subject.feature
rspec-core-2.99.0 features/subject/implicit_subject.feature
rspec-core-2.99.0.rc1 features/subject/implicit_subject.feature
rspec-core-2.14.8 features/subject/implicit_subject.feature
rspec-core-2.99.0.beta2 features/subject/implicit_subject.feature
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-core-2.14.7/features/subject/implicit_subject.feature
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-core-2.14.7/features/subject/implicit_subject.feature
dxruby_rp5-0.0.3 spec/vendor/rspec-core-2.14.7/features/subject/implicit_subject.feature
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/features/subject/implicit_subject.feature