Top Level Namespace

Defined Under Namespace

Classes: SpecInjector

Instance Method Summary collapse

Instance Method Details

#blue(text) ⇒ Object



95
96
97
# File 'lib/shared/helpers.rb', line 95

def blue text
  colorize 34, text
end

#capybara_appObject



1
2
3
4
5
6
7
8
9
# File 'lib/app/builder.rb', line 1

def capybara_app
  Rack::Builder.new do
    use SpecInjector
    use Rack::Static, urls:[ '/jasmine' ], root:'spec'
    use Rack::Static, urls:[ '/capybara-jasmine-files' ], root:gem_dir
    
    run app
  end.to_app
end

#color_print(text) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/shared/helpers.rb', line 70

def color_print text
  unless text.match /failure/
    puts red( "Jasmine specs failed to run for #{ self.inspect }." )
    return
  end

  if text.match /,\s+0 failures/
    puts cyan( text )
  else
    puts red( text )
  end
end

#colorize(color_code, text) ⇒ Object



83
84
85
# File 'lib/shared/helpers.rb', line 83

def colorize color_code, text
  "\e[#{color_code}m#{text}\e[0m"
end

#cyan(text) ⇒ Object



103
104
105
# File 'lib/shared/helpers.rb', line 103

def cyan text
  colorize 36, text
end

#display_jasmine_specsObject



36
37
38
39
# File 'lib/shared/helpers.rb', line 36

def display_jasmine_specs
  puts cyan( jasmine_suites )
  color_print jasmine_result
end

#display_js_consoleObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shared/helpers.rb', line 24

def display_js_console
  return unless Capybara.current_driver == :webkit

  if page.driver.console_messages.any?
    puts magenta( "Javascript console:")
  end

  page.driver.console_messages.each do |m|
    puts magenta( "  #{ filename_for m[ :source ]}: Line #{ m[ :line_number ]}: #{ m[ :message ]}" )
  end
end

#display_js_errorsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/shared/helpers.rb', line 6

def display_js_errors
  return unless Capybara.current_driver.match /webkit/

  if page.driver.error_messages.any?
    puts red 'Javascript errors:'
  else
    puts cyan 'No Javascript errors.'
  end

  page.driver.error_messages.each do |m|
    puts red( "  #{ filename_for m[ :source ]}: Line #{ m[ :line_number ]}: #{ m[ :message ]}" )
  end
end

#filename_for(url) ⇒ Object



20
21
22
# File 'lib/shared/helpers.rb', line 20

def filename_for url
  url.gsub /https?:\/\/.*?\//, ''
end

#gem_dirObject



12
13
14
# File 'lib/app/builder.rb', line 12

def gem_dir
  File.join(File.dirname(File.expand_path(__FILE__)), '..')
end

#green(text) ⇒ Object



91
92
93
# File 'lib/shared/helpers.rb', line 91

def green text
  colorize 32, text
end

#jasmine_failuresObject



51
52
53
54
55
56
# File 'lib/shared/helpers.rb', line 51

def jasmine_failures
  html_doc = Nokogiri::HTML( js_html )
  html_doc.css( 'div .result-message' )
          .map{|div| "  #{ div.text }"}
          .join( "\n" )
end

#jasmine_resultObject



41
42
43
44
45
46
47
48
49
# File 'lib/shared/helpers.rb', line 41

def jasmine_result
  result = js_html.match( /\d+\s+specs?,\s+\d+\s+failures?/ ).to_s

  if result.match /,\s+0 failure/
    "Jasmine Success: #{ result }"
  else
    "Jasmine Failure: #{ result }\n" + jasmine_failures
  end
end

#jasmine_suitesObject



58
59
60
61
62
63
64
# File 'lib/shared/helpers.rb', line 58

def jasmine_suites
  html_doc = Nokogiri::HTML( js_html )
  html_doc.css( 'div .suite' ).map do | suite |
    suite.at_css( '.suite-detail' ).text +
    suite.css( 'ul.specs' ).map{| spec | "\n  #{ spec.text }"}.join
  end.join
end

#js_htmlObject



66
67
68
# File 'lib/shared/helpers.rb', line 66

def js_html
  page.evaluate_script( 'document.documentElement.outerHTML' )
end

#magenta(text) ⇒ Object



99
100
101
# File 'lib/shared/helpers.rb', line 99

def magenta text
  colorize 35, text
end

#red(text) ⇒ Object



87
88
89
# File 'lib/shared/helpers.rb', line 87

def red text
  colorize 31, text
end

#run_specs(specs) ⇒ Object



1
2
3
4
# File 'lib/shared/helpers.rb', line 1

def run_specs specs
  page.driver.header 'Content-Type', 'text/html'
  page.driver.header 'X-Specs', specs
end