Class: RSpec::Clone::Dsl Private
- Inherits:
-
Object
- Object
- RSpec::Clone::Dsl
- Defined in:
- lib/r_spec/clone/dsl.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Abstract class for handling the domain-specific language.
Class Method Summary collapse
-
.before(&block) ⇒ Object
Executes the given block before each spec in the current context runs.
-
.context(_description, &block) ⇒ Object
Defines an example group that establishes a specific context, like _empty array_ versus _array with elements_.
-
.describe(const) ⇒ Object
Defines an example group that describes a unit to be tested.
-
.it(_name = nil, &block) ⇒ nil
Defines a concrete test case.
-
.its(attribute, &block) ⇒ nil
Defines a single concrete test case that specifies the actual value of an attribute of the subject using ExpectationHelper::Its#is_expected.
-
.let(name) ⇒ Symbol
Sets a user-defined property.
-
.pending(message) ⇒ nil
Defines a pending test case.
-
.subject ⇒ Symbol
Sets a user-defined property named #subject.
Class Method Details
.before(&block) ⇒ Object
Executes the given block before each spec in the current context runs.
46 47 48 49 50 51 52 53 |
# File 'lib/r_spec/clone/dsl.rb', line 46 def self.before(&block) define_method(BEFORE_METHOD) do super() instance_eval(&block) end private BEFORE_METHOD end |
.context(_description, &block) ⇒ Object
Defines an example group that establishes a specific context, like _empty array_ versus _array with elements_.
Unlike a ‘describe` block, all specifications executed within a `context` are isolated in a subprocess. This prevents possible side effects on the Ruby object environment from being propagated outside their context, which could alter the result of the unit test suite.
176 177 178 179 |
# File 'lib/r_spec/clone/dsl.rb', line 176 def self.context(_description, &block) pid = ::Process.fork { ::Class.new(self).instance_eval(&block) } exit false unless ::Process::Status.wait(pid).exitstatus.zero? end |
.describe(const) ⇒ Object
Defines an example group that describes a unit to be tested.
138 139 140 141 142 |
# File 'lib/r_spec/clone/dsl.rb', line 138 def self.describe(const, &) desc = ::Class.new(self) desc.let(:described_class) { const } if const.is_a?(::Module) desc.instance_eval(&) end |
.it(_name = nil, &block) ⇒ nil
223 224 225 226 |
# File 'lib/r_spec/clone/dsl.rb', line 223 def self.it(_name = nil, &block) Logger.source(*block.source_location) example_without_attribute.new.instance_eval(&block) end |
.its(attribute, &block) ⇒ nil
Defines a single concrete test case that specifies the actual value of an attribute of the subject using ExpectationHelper::Its#is_expected.
276 277 278 279 280 |
# File 'lib/r_spec/clone/dsl.rb', line 276 def self.its(attribute, *, **, &block) Logger.source(*block.source_location) example_with_attribute(attribute, *, **).new .instance_eval(&block) end |
.let(name) ⇒ Symbol
Sets a user-defined property.
82 83 84 85 86 |
# File 'lib/r_spec/clone/dsl.rb', line 82 def self.let(name, ...) raise Error::ReservedMethod if BEFORE_METHOD.equal?(name.to_sym) private define_method(name, ...) end |
.pending(message) ⇒ nil
Defines a pending test case.
‘&block` is never evaluated. It can be used to describe behaviour that is not yet implemented.
309 310 311 |
# File 'lib/r_spec/clone/dsl.rb', line 309 def self.pending() Logger.passed_spec Error::PendingExpectation.result() end |
.subject ⇒ Symbol
Sets a user-defined property named #subject.
116 117 118 |
# File 'lib/r_spec/clone/dsl.rb', line 116 def self.subject(&) let(__method__, &) end |