Sha256: 34604863ccb33a527308a2f507bc144565203d6ae8886ea3d92c77c32543a517

Contents?: true

Size: 1.75 KB

Versions: 51

Compression:

Stored size: 1.75 KB

Contents

Feature: Hide Defined Constant

  Use `hide_const` to remove a constant for the duration of a test.

  Scenario: Hide top-level constant
    Given a file named "hide_const_spec.rb" with:
      """ruby
      FOO = 7

      describe "hiding FOO" do
        it "can hide FOO" do
          hide_const("FOO")
          expect { FOO }.to raise_error(NameError)
        end

        it "restores the hidden constant when the example completes" do
          FOO.should eq(7)
        end
      end
      """
    When I run `rspec hide_const_spec.rb`
    Then the examples should all pass

  Scenario: Hide nested constant
    Given a file named "hide_const_spec.rb" with:
      """ruby
      module MyGem
        class SomeClass
          FOO = 7
        end
      end

      module MyGem
        describe SomeClass do
          it "hides the nested constant when it is fully qualified" do
            hide_const("MyGem::SomeClass::FOO")
            expect { SomeClass::FOO }.to raise_error(NameError)
          end

          it "restores the hidden constant when the example completes" do
            MyGem::SomeClass::FOO.should eq(7)
          end
        end
      end
      """
    When I run `rspec hide_const_spec.rb`
    Then the examples should all pass

  Scenario: Hiding undefined constant
    Given a file named "hide_const_spec.rb" with:
      """
      describe "hiding UNDEFINED_CONSTANT" do
        it "has no effect" do
          hide_const("UNDEFINED_CONSTANT")
          expect { UNDEFINED_CONSTANT }.to raise_error(NameError)
        end

        it "is still undefined after the example completes" do
          expect { UNDEFINED_CONSTANT }.to raise_error(NameError)
        end
      end
      """
    When I run `rspec hide_const_spec.rb`
    Then the examples should all pass

Version data entries

51 entries across 51 versions & 13 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.4 features/mutating_constants/hiding_defined_constant.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.3 features/mutating_constants/hiding_defined_constant.feature
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-mocks-2.13.0/features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.2 features/mutating_constants/hiding_defined_constant.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.1 features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.0 features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.0.rc1 features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.14.6 features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.99.0.beta2 features/mutating_constants/hiding_defined_constant.feature
rspec-mocks-2.14.5 features/mutating_constants/hiding_defined_constant.feature