Module: OpenHAB::RSpec::ExampleGroup::ClassMethods

Defined in:
lib/openhab/rspec/example_group.rb

Overview

Extensions for ::RSpec::ExampleGroup's singleton class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#consistent_proxies=(value) ⇒ true, ... (writeonly)

Set if Items and Thing proxies should return consistent objects.

Examples:

describe "my_rule" do
  self.consistent_proxies = false

  it "does something" do
    expect(self.class.consistent_proxies?).to be false
  end
end

Parameters:

  • value (true, false, nil)

Returns:

  • (true, false, nil)

See Also:



62
63
64
# File 'lib/openhab/rspec/example_group.rb', line 62

def consistent_proxies=(value)
  @consistent_proxies = value
end

#mock_timers=(value) ⇒ true, ... (writeonly)

Set if timers should be mocked for this example group.

Examples:

describe "my_rule" do
  self.mock_timers = false

  it "runs a timer" do
    expect(self.class.mock_timers?).to be false
  end
end

Parameters:

  • value (true, false, nil)

Returns:

  • (true, false, nil)


25
26
27
# File 'lib/openhab/rspec/example_group.rb', line 25

def mock_timers=(value)
  @mock_timers = value
end

#propagate_exceptions=(value) ⇒ true, ... (writeonly)

Set if exceptions in rules should be propagated in specs, instead of just logged.

Examples:

describe "my_rule" do
  self.propagate_exceptions = false

  it "logs exceptions in rule execution" do
    expect(self.class.propagate_exceptions?).to be false
    rule do
      on_load
      run { raise "exception is logged" }
    end
    expect(spec_log_lines).to include(match(/exception is logged/))
  end
end

Parameters:

  • value (true, false, nil)

Returns:

  • (true, false, nil)


104
105
106
# File 'lib/openhab/rspec/example_group.rb', line 104

def propagate_exceptions=(value)
  @propagate_exceptions = value
end

Instance Method Details

#consistent_proxies?true, false

If Item and Thing proxies will consistently return the same object.

Useful for mocking and using the be matcher.

It will search through parent groups until it finds one where it's explicitly defined, or defaults to true if none are.

Returns:

  • (true, false)


76
77
78
79
80
81
# File 'lib/openhab/rspec/example_group.rb', line 76

def consistent_proxies?
  return @consistent_proxies if instance_variable_defined?(:@consistent_proxies) && !@consistent_proxies.nil?
  return superclass.consistent_proxies? if superclass.is_a?(ClassMethods)

  true
end

#mock_timers?true, false

If timers are mocked for this example group

It will search through parent groups until it finds one where it's explicitly defined, or defaults to true if none are.

Returns:

  • (true, false)


37
38
39
40
41
42
# File 'lib/openhab/rspec/example_group.rb', line 37

def mock_timers?
  return @mock_timers if instance_variable_defined?(:@mock_timers) && !@mock_timers.nil?
  return superclass.mock_timers? if superclass.is_a?(ClassMethods)

  true
end

#propagate_exceptions?true, false

If timers are mocked for this example group

It will search through parent groups until it finds one where it's explicitly defined, or defaults to true if none are.

Returns:

  • (true, false)


116
117
118
119
120
121
122
123
# File 'lib/openhab/rspec/example_group.rb', line 116

def propagate_exceptions?
  if instance_variable_defined?(:@propagate_exceptions) && !@propagate_exceptions.nil?
    return @propagate_exceptions
  end
  return superclass.propagate_exceptions? if superclass.is_a?(ClassMethods)

  true
end