Class: Validator::Testee

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
spec/support/testee.rb

Direct Known Subclasses

Site, Supervisor

Constant Summary collapse

@@sentinel_errors =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sentinel_errorsObject



14
15
16
# File 'spec/support/testee.rb', line 14

def self.sentinel_errors
  @@sentinel_errors
end

Instance Method Details

#configObject



18
19
20
# File 'spec/support/testee.rb', line 18

def config
  Validator.config
end

#connected(options = {}) {|Async::Task.current, @node, @proxy| ... } ⇒ Object

Ensures that the site is connected. If the site is already connected, the block will be called immediately. Otherwise waits until the site is connected before calling the block. Use this unless there’s a specific reason to use one of the other methods. A sequence of test using ‘connected` will maintain the current connection to the site without disconnecting/reconnecting, leading to faster testing.

Yields:

  • (Async::Task.current, @node, @proxy)


28
29
30
31
32
# File 'spec/support/testee.rb', line 28

def connected options={}, &block
  start options, 'Connecting'
  wait_for_proxy
  yield Async::Task.current, @node, @proxy
end

#disconnected {|Async::Task.current| ... } ⇒ Object

Disconnects the site if connected before calling the block with a single argument ‘task`, which is an an Async::Task.

Yields:

  • (Async::Task.current)


63
64
65
66
# File 'spec/support/testee.rb', line 63

def disconnected &block
  stop 'Disconnecting'
  yield Async::Task.current
end

#isolated(options = {}) {|Async::Task.current, @node, @proxy| ... } ⇒ Object

Like ‘connected`, except that the connection is is closed after the test, before the next test is run. Use this if you somehow modify the RSMP::SiteProxy or otherwise make the current connection unstable or unusable. Because `isolated` closes the connection after the test, you ensure that the modified RSMP::SiteProxy object is discarted and following tests use a new object.

Yields:

  • (Async::Task.current, @node, @proxy)


53
54
55
56
57
58
59
# File 'spec/support/testee.rb', line 53

def isolated options={}, &block
  stop 'Isolating'
  start options, 'Connecting'
  wait_for_proxy
  yield Async::Task.current, @node, @proxy
  stop 'Isolating'
end

#reconnected(options = {}) {|Async::Task.current, @node, @proxy| ... } ⇒ Object

Disconnects the site if connected, then waits until the site is connected before calling the block. Use this if your test specifically needs to start with a fresh connection. But be aware that a fresh connection does not guarantee that the equipment will be in a pristine state. The equipment is not restarted or otherwise reset.

Yields:

  • (Async::Task.current, @node, @proxy)


40
41
42
43
44
45
# File 'spec/support/testee.rb', line 40

def reconnected options={}, &block
  stop 'Reconnecting'
  start options
  wait_for_proxy
  yield Async::Task.current, @node, @proxy
end

#stop(why = nil) ⇒ Object

Stop the rsmp supervisor



69
70
71
72
73
74
75
76
77
78
# File 'spec/support/testee.rb', line 69

def stop why=nil
  if @node
    Validator::Log.log why if why
    @node.ignore_errors RSMP::DisconnectError do
      @node.stop
    end
  end
  @node = nil
  @proxy = nil
end