konacha 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # master
2
2
 
3
+ # 1.4.2
4
+
5
+ * Update chai (1.1.1)
6
+ * Improved error messaging (rake konacha:run)
7
+ * Show pending specs in `konacha:run` output
8
+ * Colored console output
9
+
3
10
  # 1.4.1
4
11
 
5
12
  * Fix performance regression in projects which have many assets
data/README.md CHANGED
@@ -25,7 +25,7 @@ Add konacha to the `:test` and `:development` groups in the Gemfile and `bundle
25
25
 
26
26
  ```ruby
27
27
  group :test, :development do
28
- gem "konacha"
28
+ gem 'konacha'
29
29
  end
30
30
  ```
31
31
 
@@ -70,23 +70,37 @@ describe "Array#sum", ->
70
70
 
71
71
  ## Running (Rake Tasks)
72
72
 
73
- ### `rake konacha:serve`
73
+ ### In the Browser
74
74
 
75
- The `konacha:serve` rake task starts a server for your tests. You can go to the root
76
- page to run all specs (e.g. `http://localhost:3500/`), a sub page to run an individual
77
- spec file (e.g. `http://localhost:3500/array_sum_spec`), or a path to a subdirectory to
78
- run a subset of specs (e.g. `http://localhost:3500/models`).
75
+ To start a server for your tests, type:
79
76
 
80
- ### `rake konacha:run`
77
+ ```
78
+ $ bundle exec rake konacha:serve
79
+ ```
80
+
81
+ Then open [http://localhost:3500](http://localhost:3500) in your browser, and
82
+ you will see all your tests running. You can also go to a sub-page to run an
83
+ individual spec file (e.g. `http://localhost:3500/array_sum_spec`), or a path
84
+ to a subdirectory to run a subset of specs (e.g.
85
+ `http://localhost:3500/models`).
86
+
87
+ This is the recommended mode for development, since you can simply hit refresh
88
+ to reload all your test and asset files.
81
89
 
82
- The `konacha:run` rake task will let you run your tests from the command line.
90
+ ### Command-Line Runner
91
+
92
+ To run your tests from the command line, type:
93
+
94
+ ```
95
+ $ bundle exec rake konacha:run
96
+ ```
83
97
 
84
- To run individual specs, pass a comma seperated list of spec file names via the
85
- `SPEC` environment variable.
98
+ To run individual specs, pass a comma seperated list of spec file names via
99
+ the `SPEC` environment variable.
86
100
 
87
101
  ```
88
- $ rake konacha:run SPEC=foo_spec
89
- $ rake konacha:run SPEC=foo_spec,bar_spec,etc_spec
102
+ $ bundle exec rake konacha:run SPEC=foo_spec
103
+ $ bundle exec rake konacha:run SPEC=foo_spec,bar_spec,etc_spec
90
104
  ```
91
105
 
92
106
  ## Spec Helper
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  Konacha::Engine.routes.draw do
2
- match "/" => "konacha/specs#specs"
3
- match "*path" => "konacha/specs#specs"
2
+ match "/" => "specs#specs"
3
+ match "*path" => "specs#specs"
4
4
  end
data/konacha.gemspec CHANGED
@@ -17,12 +17,13 @@ the asset pipeline and engines.}
17
17
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  gem.name = "konacha"
19
19
  gem.require_paths = ["lib"]
20
- gem.version = "1.4.1"
20
+ gem.version = "1.4.2"
21
21
 
22
22
  gem.add_dependency "railties", "~> 3.1"
23
23
  gem.add_dependency "actionpack", "~> 3.1"
24
24
  gem.add_dependency "sprockets"
25
25
  gem.add_dependency "capybara"
26
+ gem.add_dependency "colorize"
26
27
 
27
28
  gem.add_development_dependency "jquery-rails"
28
29
  gem.add_development_dependency "rspec-rails"
@@ -29,6 +29,15 @@ window.Konacha = {
29
29
  });
30
30
  });
31
31
 
32
+ runner.on('pending', function (test) {
33
+ Konacha.dots += "P";
34
+ Konacha.results.push({
35
+ name:test.title,
36
+ passed:false,
37
+ pending:true
38
+ });
39
+ });
40
+
32
41
  runner.on('end', function () {
33
42
  Konacha.done = true;
34
43
  });
@@ -1,5 +1,9 @@
1
1
  module Konacha
2
2
  class Engine < Rails::Engine
3
+ # Do not mess up the application's namespace.
4
+ # http://api.rubyonrails.org/classes/Rails/Engine.html#label-Isolated+Engine
5
+ isolate_namespace Konacha
6
+
3
7
  config.konacha = ActiveSupport::OrderedOptions.new
4
8
 
5
9
  def self.application(app)
@@ -11,7 +15,7 @@ module Konacha
11
15
  end
12
16
 
13
17
  map "/" do
14
- run Konacha::Engine
18
+ run Engine
15
19
  end
16
20
  end
17
21
  end
@@ -1,4 +1,5 @@
1
1
  require "capybara"
2
+ require "colorize"
2
3
 
3
4
  module Konacha
4
5
  class Runner
@@ -22,7 +23,7 @@ module Konacha
22
23
 
23
24
  seconds = "%.2f" % (Time.now - before)
24
25
  io.puts "Finished in #{seconds} seconds"
25
- io.puts "#{examples.size} examples, #{failed_examples.size} failures"
26
+ io.puts "#{examples.size} examples, #{failed_examples.size} failures, #{pending_examples.size} pending"
26
27
  passed?
27
28
  end
28
29
 
@@ -30,8 +31,12 @@ module Konacha
30
31
  spec_runners.map { |spec_runner| spec_runner.examples }.flatten
31
32
  end
32
33
 
34
+ def pending_examples
35
+ examples.select { |example| example.pending? }
36
+ end
37
+
33
38
  def failed_examples
34
- examples.select { |example| not example.passed? }
39
+ examples.select { |example| example.failed? }
35
40
  end
36
41
 
37
42
  def passed?
@@ -67,6 +72,18 @@ module Konacha
67
72
  runner.io
68
73
  end
69
74
 
75
+ def colorize_dots(dots)
76
+ dots = dots.chars.map do |d|
77
+ case d
78
+ when 'E', 'F'; d.red
79
+ when 'P'; d.yellow
80
+ when '.'; d.green
81
+ else; d
82
+ end
83
+ end
84
+ dots.join ''
85
+ end
86
+
70
87
  def run
71
88
  session.visit(spec.url)
72
89
 
@@ -75,7 +92,7 @@ module Konacha
75
92
  sleep 0.1
76
93
  done, dots = session.evaluate_script('[Konacha.done, Konacha.dots]')
77
94
  if dots
78
- io.write dots[dots_printed..-1]
95
+ io.write colorize_dots(dots[dots_printed..-1])
79
96
  io.flush
80
97
  dots_printed = dots.length
81
98
  end
@@ -85,7 +102,9 @@ module Konacha
85
102
  Example.new(row)
86
103
  end
87
104
  rescue => e
88
- raise Konacha::Error, "Error communicating with browser process: #{e.inspect}"
105
+ msg = [e.inspect]
106
+ msg << e.message unless e.message.blank?
107
+ raise Konacha::Error, "Error communicating with browser process:\n#{msg.join("\n")}"
89
108
  end
90
109
  end
91
110
 
@@ -98,13 +117,23 @@ module Konacha
98
117
  @row['passed']
99
118
  end
100
119
 
120
+ def pending?
121
+ @row['pending']
122
+ end
123
+
124
+ def failed?
125
+ !(@row['passed'] || @row['pending'])
126
+ end
127
+
101
128
  def failure_message
102
- unless passed?
129
+ if failed?
103
130
  msg = []
104
131
  msg << " Failed: #{@row['name']}"
105
132
  msg << " #{@row['message']}"
106
133
  msg << " in #{@row['trace']['fileName']}:#{@row['trace']['lineNumber']}" if @row['trace']
107
- msg.join("\n")
134
+ msg.join("\n").red
135
+ elsif pending?
136
+ " Pending: #{@row['name']}".yellow
108
137
  end
109
138
  end
110
139
  end
@@ -0,0 +1,3 @@
1
+ describe("pending test", function(){
2
+ it("is pending");
3
+ });
data/spec/runner_spec.rb CHANGED
@@ -15,12 +15,17 @@ describe Konacha::Runner do
15
15
  it "prints results to the output" do
16
16
  buffer.rewind
17
17
  results = buffer.read
18
+ # Strip colors
19
+ results.gsub!(/\e\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/, '')
18
20
  # Failure output present?
19
21
  results.should include 'F'
20
22
  results.should include 'expected 4 to equal 5'
23
+ # Pending output present?
24
+ results.should include 'P'
25
+ results.should include 'is pending'
21
26
  # Summary and dots
22
- results.should include "#{runner.examples.length} examples, 1 failure"
23
- results.should match /^[.F]{#{runner.examples.length}}$/
27
+ results.should include "#{runner.examples.length} examples, 1 failures, 1 pending"
28
+ results.should match /^[.FP]{#{runner.examples.length}}$/
24
29
  end
25
30
  end
26
31
  end