Class: JazzMoney::RspecThread

Inherits:
Object
  • Object
show all
Defined in:
lib/jazz_money/rspec_thread.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suites, jasmine_reporter) ⇒ RspecThread

Returns a new instance of RspecThread.



16
17
18
19
# File 'lib/jazz_money/rspec_thread.rb', line 16

def initialize(suites, jasmine_reporter)
  @suites = suites
  @jasmine_reporter = jasmine_reporter
end

Instance Attribute Details

#jasmine_reporterObject (readonly)

Returns the value of attribute jasmine_reporter.



6
7
8
# File 'lib/jazz_money/rspec_thread.rb', line 6

def jasmine_reporter
  @jasmine_reporter
end

Class Method Details

.start(suites, jasmine_reporter) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/jazz_money/rspec_thread.rb', line 8

def self.start(suites, jasmine_reporter)
  t = Thread.start do
    me = new(suites, jasmine_reporter)
    me.run
  end
  t
end

Instance Method Details

#declare_spec(parent, spec) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jazz_money/rspec_thread.rb', line 49

def declare_spec(parent, spec)
  me = self
  example_name = spec["name"]
  spec_id = spec['id']
  parent.it example_name do
    while me.jasmine_reporter.results[spec_id].nil?
      sleep 0.2
    end
    me.report_spec(me.jasmine_reporter.results[spec_id])
  end
end

#declare_suite(parent, suite) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jazz_money/rspec_thread.rb', line 33

def declare_suite(parent, suite)
  me = self
  parent.describe suite["name"] do
    suite["children"].each do |suite_or_spec|
      type = suite_or_spec["type"]
      if type == "suite"
        me.declare_suite(self, suite_or_spec)
      elsif type == "spec"
        me.declare_spec(self, suite_or_spec)
      else
        raise "unknown type #{type} for #{suite_or_spec.inspect}"
      end
    end
  end
end

#declare_suitesObject



26
27
28
29
30
31
# File 'lib/jazz_money/rspec_thread.rb', line 26

def declare_suites
  me = self
  @suites.each do |suite|
    declare_suite(self, suite)
  end
end

#report_spec(spec_results) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jazz_money/rspec_thread.rb', line 61

def report_spec(spec_results)
  if (spec_results['result'] != 'passed')

    fail_messages_hashes = spec_results['messages'].reject {|message| message["message"] =~ /Passed/}
    all_fail_messages = []
    fail_messages_hashes.each do |message|
      all_fail_messages << message["message"]
      js_stack_lines = message["stack_trace"].split("\n").select {|stack_line| stack_line =~ /spec\/javascript/}
      js_stack_lines.each {|stack_line| all_fail_messages << stack_line.gsub("()@", "./")}
    end

    Spec::Expectations.fail_with(all_fail_messages.join("\n"))
  end
end

#runObject



21
22
23
24
# File 'lib/jazz_money/rspec_thread.rb', line 21

def run
  declare_suites
  Spec::Runner.run
end