Class: Specifier::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/specifier/example.rb

Overview

Configures an example (used for it statements).

Usage:

example = Specifier::Example.new("...") do
  expect(value).to equal(value)
end

example.run

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, &block) ⇒ Example

Returns a new instance of Example.



18
19
20
21
# File 'lib/specifier/example.rb', line 18

def initialize(description, &block)
  @description = description
  @block = block
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



16
17
18
# File 'lib/specifier/example.rb', line 16

def description
  @description
end

Instance Method Details

#equal(value) ⇒ Object



27
28
29
# File 'lib/specifier/example.rb', line 27

def equal(value)
  Matcher::Equal.new(value)
end

#expect(value) ⇒ Object



23
24
25
# File 'lib/specifier/example.rb', line 23

def expect(value)
  Expectation.new(value)
end

#runObject



31
32
33
34
35
36
# File 'lib/specifier/example.rb', line 31

def run
  instance_eval(&@block)
  return Result.new(:pass)
rescue Specifier::Expectation::Miss => miss
  return Result.new(:fail, miss.message)
end