Class: Stendhal::Example

Inherits:
Object show all
Includes:
Matchers, Mocks
Defined in:
lib/stendhal/example.rb

Constant Summary collapse

@@examples =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mocks

#double

Methods included from Matchers

#be_a, #eq, #method_missing

Constructor Details

#initialize(docstring, options = {}, &block) ⇒ Example

Returns a new instance of Example.



13
14
15
16
17
18
# File 'lib/stendhal/example.rb', line 13

def initialize(docstring, options = {}, &block)
  @description = docstring
  @block = block
  @pending = true if options[:pending] || !block_given?
  @@examples << self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stendhal::Matchers

Instance Attribute Details

#aborted_messageObject (readonly)

Returns the value of attribute aborted_message.



11
12
13
# File 'lib/stendhal/example.rb', line 11

def aborted_message
  @aborted_message
end

#blockObject (readonly)

Returns the value of attribute block.



9
10
11
# File 'lib/stendhal/example.rb', line 9

def block
  @block
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/stendhal/example.rb', line 8

def description
  @description
end

#failed_messageObject (readonly)

Returns the value of attribute failed_message.



10
11
12
# File 'lib/stendhal/example.rb', line 10

def failed_message
  @failed_message
end

Class Method Details

.countObject



63
64
65
# File 'lib/stendhal/example.rb', line 63

def count
  @@examples.count
end

.destroy_allObject



59
60
61
# File 'lib/stendhal/example.rb', line 59

def destroy_all
  @@examples = []
end

Instance Method Details

#aborted?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/stendhal/example.rb', line 45

def aborted?
  @aborted
end

#destroyObject



49
50
51
# File 'lib/stendhal/example.rb', line 49

def destroy
  @@examples.delete self
end

#fail(message = 'failed') ⇒ Object



53
54
55
# File 'lib/stendhal/example.rb', line 53

def fail(message = 'failed')
  raise Stendhal::Exceptions::ExpectationNotMet.new(message)
end

#failed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/stendhal/example.rb', line 41

def failed?
  @failed
end

#pending?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/stendhal/example.rb', line 37

def pending?
  @pending
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stendhal/example.rb', line 20

def run
  begin
    Stendhal::Mocks::MockVerifier.reset!
    self.instance_eval(&@block)
    Stendhal::Mocks::MockVerifier.verify!
    return 0
  rescue Exceptions::ExpectationNotMet=>e
    @failed = true
    @failed_message = e.message
    return 1
  rescue StandardError=>e
    @aborted = true
    @aborted_message = e.message
    return 1
  end
end