Module: Validator

Extended by:
RSMP::Logging
Includes:
RSpec::Matchers
Defined in:
spec/support/validator.rb,
spec/support/log_helpers.rb,
spec/support/formatters/list.rb,
spec/support/formatters/brief.rb,
spec/support/formatters/steps.rb,
spec/support/handshake_helper.rb,
spec/support/formatters/details.rb,
spec/support/interaction_helpers.rb,
spec/support/formatters/report_stream.rb,
spec/support/formatters/formatter_base.rb

Defined Under Namespace

Modules: CommandHelpers, HandshakeHelper, Log, StatusHelpers Classes: Brief, Details, FormatterBase, List, ReportStream, Site, Steps, Supervisor, Testee

Constant Summary collapse

@@reactor =
nil

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



10
11
12
# File 'spec/support/validator.rb', line 10

def config
  @config
end

.loggerObject

Returns the value of attribute logger.



10
11
12
# File 'spec/support/validator.rb', line 10

def logger
  @logger
end

.modeObject

Returns the value of attribute mode.



10
11
12
# File 'spec/support/validator.rb', line 10

def mode
  @mode
end

.reporterObject

Returns the value of attribute reporter.



10
11
12
# File 'spec/support/validator.rb', line 10

def reporter
  @reporter
end

.site_validatorObject

Returns the value of attribute site_validator.



11
12
13
# File 'spec/support/validator.rb', line 11

def site_validator
  @site_validator
end

.supervisor_validatorObject

Returns the value of attribute supervisor_validator.



11
12
13
# File 'spec/support/validator.rb', line 11

def supervisor_validator
  @supervisor_validator
end

Class Method Details

.around_each(example) ⇒ Object

called by rspec when each example is being run



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'spec/support/validator.rb', line 73

def self.around_each example
  thread_local_data = RSpec::Support.thread_local_data
  reactor.run do |task|
    # rspec depends on thread-local data (which is actually fiber-local),
    # but the async task runs in a different fiber. as a work-around,
    # we copy the data into the current fiber-local storage
    thread_local_data.each_pair { |key,value| RSpec::Support.thread_local_data[key] = value }
    task.annotate 'rspec'
    example.run
  ensure
    reactor.interrupt
  end
end

.before_suite(examle) ⇒ Object

called by rspec at startup



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'spec/support/validator.rb', line 51

def self.before_suite examle
  @@reactor = Async::Reactor.new
  reactor.annotate 'reactor'
  error = nil
  reactor.run do |task|
    Validator.check_connection
  rescue StandardError => e
    error = e
    task.stop
  ensure
    reactor.interrupt
  end
  raise error if error
rescue RSMP::ConnectionError => e
  STDERR.puts "Aborting: #{e.message}".colorize(:red)
  raise
rescue StandardError => e
  STDERR.puts "Aborting: #{e.inspect}".colorize(:red)
  raise
end

.check_connectionObject

initial check that we have a connection to the site/supervisor



88
89
90
91
92
93
94
95
96
# File 'spec/support/validator.rb', line 88

def self.check_connection
  Validator::Log.log "Initial #{self.mode} connection check"
  if self.mode == :site
    Validator::Site.testee.connected {}
  elsif self.mode == :supervisor
    Validator::Supervisor.testee.connected {}
  end
  self.log ""
end

.log(str, options = {}) ⇒ Object

log to the rspec formatter



99
100
101
# File 'spec/support/validator.rb', line 99

def self.log str, options={}
  self.reporter.publish :step, message: str
end

.reactorObject

get our global reactor



17
18
19
# File 'spec/support/validator.rb', line 17

def self.reactor
  @@reactor
end

.setup(rspec_config) ⇒ Object



21
22
23
24
25
26
27
# File 'spec/support/validator.rb', line 21

def self.setup rspec_config
  determine_mode rspec_config.files_to_run
  load_config
  setup_logging rspec_config
  build_testee
  setup_filters rspec_config
end

.setup_logging(rspec_config) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'spec/support/validator.rb', line 29

def self.setup_logging rspec_config
  settings = {
    'stream' => ReportStream.new(rspec_config.reporter),
    'color' => {
      'info' => 'light_black',
      'log' => 'white',
      'test' => 'white',
      'debug' => 'light_black'
    },
    'port' => true,
    'json' => true,
    'acknowledgements' => true,
    'watchdogs' => true,
    'test' => true,
    'debug' => true
  }
  settings = settings.deep_merge(config['log']) if config['log']
  initialize_logging log_settings: settings
  self.reporter = rspec_config.reporter
end

.warning(str, options = {}) ⇒ Object

log to the rspec formatter



104
105
106
# File 'spec/support/validator.rb', line 104

def self.warning str, options={}
  self.reporter.publish :warning, message: str
end

Instance Method Details

#ask_user(site, question, accept: '') ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'spec/support/interaction_helpers.rb', line 2

def ask_user site, question, accept:''
  async_stdin = Async::IO::Stream.new( Async::IO::Generic.new($stdin) )
  pointing = "\u{1f449}"
  print "#{pointing} " + question.colorize(:color => :light_magenta) + " "
  site.log "Asking user for input: #{question}", level: :test
  response = async_stdin.gets.chomp
  if response == accept
    site.log "OK from user", level: :test
  else
    site.log "Test skipped by user", level: :test
    expect(response).to eq(accept), "Test skipped by user"
  end
end