Class: Jasmine::RspecFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine/rspec_formatter.rb

Instance Method Summary collapse

Instance Method Details

#declare_spec(parent, spec) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jasmine/rspec_formatter.rb', line 32

def declare_spec(parent, spec)
  me = self
  example_name = spec["name"]
  backtrace = @results.example_location_for(parent.description + " " + example_name)
  if Jasmine::Dependencies.rspec2?
    parent.it example_name, {} do
      me.report_spec(spec["id"])
    end
  else
    parent.it example_name, {}, backtrace do
      me.report_spec(spec["id"])
    end
  end
end

#declare_suites(suites) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/jasmine/rspec_formatter.rb', line 11

def declare_suites(suites)
  suites.each do |suite|
    #empty block for rspec 1
    group = example_group(suite["name"]) {}
    process_children(group, suite["children"])
  end
end

#format_results(results) ⇒ Object



6
7
8
9
# File 'lib/jasmine/rspec_formatter.rb', line 6

def format_results(results)
  @results = results
  declare_suites(@results.suites)
end

#process_children(parent, children) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jasmine/rspec_formatter.rb', line 19

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

#report_spec(spec_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jasmine/rspec_formatter.rb', line 47

def report_spec(spec_id)
  spec_results = results_for(spec_id)
  out = ""
  messages = spec_results['messages'].each do |message|
    case
    when message["type"] == "log"
      puts message["text"]
      puts "\n"
    else
      unless message["message"] =~ /^Passed.$/
        STDERR << message["message"]
        STDERR << "\n"

        out << message["message"]
        out << "\n"
      end

      if !message["passed"] && message["trace"]["stack"]
        stack_trace = message["trace"]["stack"].gsub(/<br \/>/, "\n").gsub(/<\/?b>/, " ")
        STDERR << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/")
        STDERR << "\n"
      end
    end

  end
  fail out unless spec_results['result'] == 'passed'
  puts out unless out.empty?
end