chinchilla 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/chinchilla.gemspec CHANGED
@@ -8,13 +8,13 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Chinchilla::VERSION
9
9
  gem.authors = ["tchak"]
10
10
  gem.email = ["paul@chavard.net"]
11
- gem.description = %q{QUnit test runner}
12
- gem.summary = %q{Run QUnit test on Capybara}
11
+ gem.description = %q{mocha test runner}
12
+ gem.summary = %q{Run mocha test on Capybara}
13
13
  gem.homepage = ""
14
14
 
15
15
  gem.add_dependency 'capybara'
16
16
  gem.add_dependency 'poltergeist'
17
- gem.add_dependency 'colorize'
17
+ gem.add_dependency 'rocha'
18
18
 
19
19
  gem.files = `git ls-files`.split($\)
20
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,23 +1,18 @@
1
- require 'chinchilla/runner/example'
2
- require 'chinchilla/runner/test'
3
-
4
1
  module Chinchilla
5
2
  class Runner
6
- def self.run(options={})
7
- self.new(options).run
3
+ def self.start(options={})
4
+ new(options).run
8
5
  end
9
6
 
7
+ attr_reader :reporter
8
+
10
9
  def initialize(options)
11
- options[:urls] = [options.delete(:url)] if options.has_key?(:url)
12
10
  @options = options
11
+ @reporter = Rocha::Reporter.new(*formatters)
13
12
  end
14
13
 
15
- def io
16
- @io ||= @options[:io] || STDOUT
17
- end
18
-
19
- def urls
20
- @urls ||= @options[:urls] || ['/']
14
+ def url
15
+ @url ||= @options[:url] || '/'
21
16
  end
22
17
 
23
18
  def driver
@@ -28,64 +23,54 @@ module Chinchilla
28
23
  driver == :poltergeist
29
24
  end
30
25
 
31
- def application
32
- @application ||= @options[:application] || default_application
33
- end
34
-
35
- def default_application
36
- defined?(Rails) ? Rails.application : nil
37
- end
38
-
39
- def tests
40
- @tests ||= urls.map {|url| Test.new(self, url) }
41
- end
42
-
43
26
  def run
44
- before = Time.now
45
-
46
- io.puts ""
47
- io.puts dots.to_s
48
- io.puts ""
49
- if failure_messages
50
- io.puts failure_messages
51
- io.puts ""
52
- end
27
+ session.visit(url)
28
+
29
+ events_consumed = 0
30
+ done = false
31
+ begin
32
+ sleep 0.1
33
+ events = JSON.parse(session.evaluate_script('window.mocha.getEvents()'))
34
+ if events
35
+ events[events_consumed..-1].each do |event|
36
+ done = true if event['event'] == 'end'
37
+ reporter.process_mocha_event(event)
38
+ end
39
+
40
+ events_consumed = events.length
41
+ end
42
+ end until done
53
43
 
54
- seconds = "%.2f" % (Time.now - before)
55
- io.puts "Finished in #{seconds} seconds"
56
- io.puts "#{examples.size} assertions, #{failed_examples.size} failures"
57
- passed?
44
+ reporter.passed?
45
+ rescue => e
46
+ raise e, "Error communicating with browser process: #{e}", e.backtrace
58
47
  end
59
48
 
60
- def examples
61
- tests.map { |test| test.examples }.flatten
49
+ def session
50
+ @session ||= begin
51
+ if poltergeist? && !defined?(Capybara::Poltergeist)
52
+ require "capybara/poltergeist"
53
+ end
54
+ Capybara::Session.new(driver, application)
55
+ end
62
56
  end
63
57
 
64
- def failed_examples
65
- examples.select { |example| not example.passed? }
66
- end
58
+ private
67
59
 
68
- def passed?
69
- tests.all? { |test| test.passed? }
60
+ def application
61
+ @application ||= @options[:application] || default_application
70
62
  end
71
63
 
72
- def dots
73
- tests.map { |test| test.dots }.join
64
+ def formatters
65
+ @formatters ||= @options[:formatters] || default_formatters
74
66
  end
75
67
 
76
- def failure_messages
77
- unless passed?
78
- tests.map { |test| test.failure_messages }.compact.join("\n\n")
79
- end
68
+ def default_application
69
+ defined?(Rails) ? Rails.application : nil
80
70
  end
81
71
 
82
- def session
83
- @session ||= begin
84
- if poltergeist? && !defined?(Capybara::Poltergeist)
85
- require "capybara/poltergeist"
86
- end
87
- Capybara::Session.new(driver, application)
88
- end
72
+ def default_formatters
73
+ [Rocha::Formatter.new(STDOUT)]
89
74
  end
90
75
  end
91
76
  end
@@ -1,3 +1,3 @@
1
1
  module Chinchilla
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/chinchilla.rb CHANGED
@@ -1,13 +1,9 @@
1
- require "chinchilla/version"
2
-
3
1
  require "capybara"
4
- require "colorize"
5
-
2
+ require "rocha"
6
3
  require "chinchilla/runner"
7
4
 
8
- if defined?(::Rails)
9
- module Chinchilla
10
- class Engine < ::Rails::Engine
11
- end
5
+ module Chinchilla
6
+ def self.start(options={})
7
+ Runner.start(options)
12
8
  end
13
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chinchilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-29 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: colorize
47
+ name: rocha
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- description: QUnit test runner
62
+ description: mocha test runner
63
63
  email:
64
64
  - paul@chavard.net
65
65
  executables: []
@@ -74,9 +74,6 @@ files:
74
74
  - chinchilla.gemspec
75
75
  - lib/chinchilla.rb
76
76
  - lib/chinchilla/runner.rb
77
- - lib/chinchilla/runner/example.rb
78
- - lib/chinchilla/runner/runner.js
79
- - lib/chinchilla/runner/test.rb
80
77
  - lib/chinchilla/version.rb
81
78
  homepage: ''
82
79
  licenses: []
@@ -90,22 +87,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
87
  - - ! '>='
91
88
  - !ruby/object:Gem::Version
92
89
  version: '0'
93
- segments:
94
- - 0
95
- hash: 2808188431047913734
96
90
  required_rubygems_version: !ruby/object:Gem::Requirement
97
91
  none: false
98
92
  requirements:
99
93
  - - ! '>='
100
94
  - !ruby/object:Gem::Version
101
95
  version: '0'
102
- segments:
103
- - 0
104
- hash: 2808188431047913734
105
96
  requirements: []
106
97
  rubyforge_project:
107
98
  rubygems_version: 1.8.23
108
99
  signing_key:
109
100
  specification_version: 3
110
- summary: Run QUnit test on Capybara
101
+ summary: Run mocha test on Capybara
111
102
  test_files: []
@@ -1,23 +0,0 @@
1
- module Chinchilla
2
- class Runner
3
- class Example
4
- def initialize(row)
5
- @row = row
6
- end
7
-
8
- def passed?
9
- @row['passed']
10
- end
11
-
12
- def failure_message
13
- unless passed?
14
- msg = []
15
- msg << " Failed: #{@row['name']}"
16
- msg << " #{@row['message']}"
17
- msg << " in #{@row['trace']}" if @row['trace']
18
- msg.join("\n")
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,40 +0,0 @@
1
- QUnit.Runner = {
2
- done: false,
3
- dots: "",
4
- results: []
5
- };
6
-
7
- QUnit.Runner.getResults = function() {
8
- return JSON.stringify(QUnit.Runner.results);
9
- };
10
-
11
- var currentTest = {};
12
- QUnit.testDone = function(results) {
13
- QUnit.Runner.dots += (results.failed > 0 ? "F" : ".");
14
- QUnit.Runner.results.push({
15
- name: results.name,
16
- passed: results.failed === 0,
17
- message: currentTest.message
18
- });
19
-
20
- currentTest = {};
21
- };
22
-
23
- QUnit.log = function(results) {
24
- if (!results.result) {
25
- var message;
26
- if (results.message) {
27
- message = results.message;
28
- } else {
29
- message = "Expected '"+results.expected+"', got '"+results.actual+"'";
30
- }
31
- currentTest.message = message;
32
- currentTest.trace = results.source;
33
- }
34
- };
35
-
36
- QUnit.done = function(results) {
37
- QUnit.Runner.done = true;
38
- };
39
-
40
- QUnit.config.autorun = false;
@@ -1,85 +0,0 @@
1
- module Chinchilla
2
- class Runner
3
- class Test
4
- attr_reader :runner, :url
5
-
6
- def initialize(runner, url)
7
- @runner = runner
8
- @url = url
9
- end
10
-
11
- def session
12
- runner.session
13
- end
14
-
15
- def io
16
- runner.io
17
- end
18
-
19
- def run
20
- io.puts dots
21
- io.puts failure_messages
22
- io.puts "\n#{examples.size} assertions, #{failed_examples.size} failures"
23
- passed?
24
- end
25
-
26
- def colorize_dots(dots)
27
- dots = dots.chars.map do |d|
28
- case d
29
- when 'E', 'F'; d.red
30
- when 'P'; d.yellow
31
- when '.'; d.green
32
- else; d
33
- end
34
- end
35
- dots.join ''
36
- end
37
-
38
- def examples
39
- @results ||= begin
40
- session.visit(url)
41
-
42
- session.execute_script(runner_js)
43
-
44
- dots_printed = 0
45
-
46
- begin
47
- sleep 0.1
48
- done, dots = session.evaluate_script('[QUnit.Runner.done, QUnit.Runner.dots]')
49
- if dots
50
- io.write colorize_dots(dots[dots_printed..-1])
51
- io.flush
52
- dots_printed = dots.length
53
- end
54
- end until done
55
-
56
- JSON.parse(session.evaluate_script('QUnit.Runner.getResults()')).map do |row|
57
- Example.new(row)
58
- end
59
- end
60
- end
61
-
62
- def runner_js
63
- "(function() {"+File.read(File.expand_path("../runner.js", __FILE__))+"})();"
64
- end
65
-
66
- def failed_examples
67
- examples.select { |example| not example.passed? }
68
- end
69
-
70
- def passed?
71
- examples.all? { |example| example.passed? }
72
- end
73
-
74
- def dots
75
- examples; ""
76
- end
77
-
78
- def failure_messages
79
- unless passed?
80
- examples.map { |example| example.failure_message }.compact.join("\n\n")
81
- end
82
- end
83
- end
84
- end
85
- end