Class: Tengu::ItBlock

Inherits:
Object
  • Object
show all
Includes:
Matchers
Defined in:
lib/tengu/it_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Matchers

#be, #be_false, #be_instance_of, #be_kind_of, #be_nil, #be_true, #eq, #eql, #equal, #have_received, #include, #match

Constructor Details

#initialize(describe_block, description, block) ⇒ ItBlock

Returns a new instance of ItBlock.



11
12
13
14
15
16
17
18
19
# File 'lib/tengu/it_block.rb', line 11

def initialize(describe_block, description, block)
  @describe_block = describe_block
  @description = description
  @block = block
  @success = true
  @pending = false
  @expectations = []
  @error = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



88
89
90
# File 'lib/tengu/it_block.rb', line 88

def method_missing(method, *args, &block)
  @describe_block.send(method, *args, &block)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/tengu/it_block.rb', line 9

def description
  @description
end

#expectationsObject (readonly)

Returns the value of attribute expectations.



9
10
11
# File 'lib/tengu/it_block.rb', line 9

def expectations
  @expectations
end

Instance Method Details

#errored?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/tengu/it_block.rb', line 32

def errored?
  @error
end

#pending?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tengu/it_block.rb', line 42

def pending?
  @pending
end

#run(listeners = []) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/tengu/it_block.rb', line 21

def run(listeners = [])
  @listeners = listeners
  begin
    instance_eval(&@block)
  rescue Exception => e
    @error = e
    @success = false
  end
  notify(@listeners)
end

#success?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/tengu/it_block.rb', line 36

def success?
  unless pending? || errored?
    @expectations.all? { |expectation| expectation.success? }
  end
end