Class: RSpec::Dsl
- Inherits:
-
Object
- Object
- RSpec::Dsl
- Defined in:
- lib/r_spec/dsl.rb
Overview
Abstract class for handling the domain-specific language.
Class Method Summary collapse
-
.after(&block) ⇒ Object
Executes the given block after each spec in the current context runs.
-
.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, &block) ⇒ Object
Defines an example group that describes a unit to be tested.
-
.it(_name = nil, &block) ⇒ nil
Defines a concrete test case.
-
.its(attribute, *args, **kwargs, &block) ⇒ nil
Use the Dsl.its method to define a single spec that specifies the actual value of an attribute of the subject using ExpectationHelper::Its#is_expected.
-
.let(name, *args, **kwargs, &block) ⇒ Symbol
Sets a user-defined property.
-
.pending(message) ⇒ nil
Defines a pending test case.
-
.subject(&block) ⇒ Symbol
Sets a user-defined property named #subject.
Class Method Details
.after(&block) ⇒ Object
Executes the given block after each spec in the current context runs.
73 74 75 76 77 78 79 80 |
# File 'lib/r_spec/dsl.rb', line 73 def self.after(&block) define_method(AFTER_METHOD) do instance_exec(&block) super() end private AFTER_METHOD end |
.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/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 describe, the block is evaluated in isolation in order to scope possible side effects inside its context.
183 184 185 186 |
# File 'lib/r_spec/dsl.rb', line 183 def self.context(_description, &block) desc = ::Class.new(self) ::Aw.fork! { desc.instance_eval(&block) } end |
.describe(const, &block) ⇒ Object
Defines an example group that describes a unit to be tested.
151 152 153 154 155 |
# File 'lib/r_spec/dsl.rb', line 151 def self.describe(const, &block) desc = ::Class.new(self) desc.let(:described_class) { const } if const.is_a?(::Module) desc.instance_eval(&block) end |
.it(_name = nil, &block) ⇒ nil
226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/r_spec/dsl.rb', line 226 def self.it(_name = nil, &block) raise ::ArgumentError, "Missing example block" unless block example = ::Class.new(self) { include ExpectationHelper::It }.new example.instance_eval(&block) rescue ::SystemExit Console.source(*block.source_location) exit false ensure example&.send(AFTER_METHOD) end |
.its(attribute, *args, **kwargs, &block) ⇒ nil
Use the its method to define a single spec that specifies the actual value of an attribute of the subject using ExpectationHelper::Its#is_expected.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/r_spec/dsl.rb', line 284 def self.its(attribute, *args, **kwargs, &block) raise ::ArgumentError, "Missing example block" unless block example = ::Class.new(self) do include ExpectationHelper::Its define_method(:actual) do subject.public_send(attribute, *args, **kwargs) end end.new example.instance_eval(&block) rescue ::SystemExit Console.source(*block.source_location) exit false ensure example&.send(AFTER_METHOD) end |
.let(name, *args, **kwargs, &block) ⇒ Symbol
Sets a user-defined property.
107 108 109 110 111 |
# File 'lib/r_spec/dsl.rb', line 107 def self.let(name, *args, **kwargs, &block) raise Error::ReservedMethod if [BEFORE_METHOD, AFTER_METHOD].include?(name.to_sym) private define_method(name, *args, **kwargs, &block) 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.
329 330 331 |
# File 'lib/r_spec/dsl.rb', line 329 def self.pending() Console.passed_spec Error::PendingExpectation.result() end |
.subject(&block) ⇒ Symbol
Sets a user-defined property named #subject.
131 132 133 |
# File 'lib/r_spec/dsl.rb', line 131 def self.subject(&block) let(__method__, &block) end |