/usr/share/doc/ruby-rspec-mocks/features/mutating_constants/hide_defined_constant.feature is in ruby-rspec-mocks 3.4.0c3e0m1s1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 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
RSpec.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
expect(FOO).to 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
RSpec.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
expect(MyGem::SomeClass::FOO).to 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:
"""ruby
RSpec.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
|