Module: Belly::Client

Included in:
Belly
Defined in:
lib/belly/client.rb,
lib/belly/client/config.rb,
lib/belly/client/hub_proxy.rb,
lib/belly/client/default_config.rb

Defined Under Namespace

Classes: Config, DefaultConfig, HubProxy, NoSuchProjectError

Instance Method Summary collapse

Instance Method Details

#configObject



36
37
38
# File 'lib/belly/client.rb', line 36

def config
  @config ||= Config.new
end

#hubObject



40
41
42
# File 'lib/belly/client.rb', line 40

def hub
  @hub ||= HubProxy.new(config)
end

#publish(scenario) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/belly/client.rb', line 3

def publish(scenario)
  return if offline?
  
  feature_name = scenario.feature.name.split("\n").first # TODO: only needed for older cucumbers
  feature_file, line = scenario.file_colon_line.split(':')

  data = Messages::CucumberScenarioResultMessage.new(
    feature_name, 
    scenario,
    config.user,
    config.project,
    feature_file,
    line).to_json

  Belly.log("publishing #{data}")

  # Break out a thread so we don't slow down the tests
  thread = Thread.new { hub.post_test_result(data) }

  # Make sure the thread gets a chance to finish before the process exits
  at_exit do
    begin
      thread.join
    rescue SocketError, Errno::ECONNREFUSED => exception
      # TODO: test this
      unless offline?
        warn("Belly couldn't send your results to the server (#{Belly.config.url}).")
        offline!
      end
    end
  end
end