konacha 0.10.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- # This is a runtime dependency in the gemspec, so it shouldn't be necessary to
5
- # specify it again, but bundler is buggy:
6
- # https://github.com/carlhuda/bundler/issues/1041
7
- gem "jquery-rails"
data/History.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # master
2
2
 
3
+ # 1.0.0-rc1
4
+
5
+ * Do not time out after 300 seconds
6
+ * Rename #test div to #konacha
7
+ * Update vendored copies of mocha (1.0.0+) and chai (0.5.2+)
8
+ * jQuery is no longer included by default
9
+ * Fully remove and replace the #konacha element (#23)
10
+ * Remove the `interface` configuration option. A future version will support
11
+ all Mocha configuration options, but configuration will be done in JS, not Ruby.
12
+
3
13
  # 0.10.0
4
14
 
5
15
  * Rename `konacha:ci` and `konacha:server` task to `konacha:run` and
data/README.md CHANGED
@@ -7,13 +7,15 @@ assertion library.
7
7
  [![Konacha][2]][1]
8
8
 
9
9
  [1]: http://en.wikipedia.org/wiki/Konacha
10
- [2]: https://github.com/jfirebaugh/konacha/raw/master/vendor/assets/images/konacha.jpg
10
+ [2]: https://github.com/jfirebaugh/konacha/raw/master/vendor/images/konacha.jpg
11
11
 
12
12
  It is similar to [Jasmine](https://github.com/pivotal/jasmine-gem) and
13
13
  [Evergreen](https://github.com/jnicklas/evergreen), but does not attempt to be framework
14
14
  agnostic. By sticking with Rails, Konacha can take full advantage of features such as
15
15
  the asset pipeline and engines.
16
16
 
17
+ Photo credit: [FCartegnie](http://commons.wikimedia.org/wiki/File:Konacha.jpg), CC-BY-SA.
18
+
17
19
  ## Installation
18
20
 
19
21
  Add konacha to the `:test` and `:development` groups in the Gemfile and `bundle install`:
@@ -61,7 +63,7 @@ page to run all specs (e.g. `http://localhost:3500/`), a sub page to run an indi
61
63
  spec file (e.g. `http://localhost:3500/array_sum_spec`), or a path to a subdirectory to
62
64
  run a subset of specs (e.g. `http://localhost:3500/models`).
63
65
 
64
- Alternatively, you can run the specs headlessly with the `konacha:run` task.
66
+ Alternatively, you can run the specs in your shell with the `konacha:run` task.
65
67
 
66
68
  ## Spec Helper
67
69
 
@@ -94,15 +96,13 @@ Konacha can be configured in an initializer, e.g. `config/initializers/konacha.r
94
96
 
95
97
  Konacha.configure do |config|
96
98
  config.spec_dir = "spec/javascripts"
97
- config.interface = :bdd
98
99
  config.driver = :selenium
99
100
  end if defined?(Konacha)
100
101
 
101
102
  The `defined?` check is necessary to avoid a dependency on Konacha in the production
102
103
  environment.
103
104
 
104
- The `spec_dir` option tells Konacha where to find JavaScript specs. The `interface`
105
- option specifies the test interface used by Mocha (see below). `driver` names a
105
+ The `spec_dir` option tells Konacha where to find JavaScript specs. `driver` names a
106
106
  Capybara driver used for the `run` task (try `:webkit`, after installing
107
107
  [capybara-webkit](https://github.com/thoughtbot/capybara-webkit)).
108
108
 
@@ -111,16 +111,8 @@ The values above are the defaults.
111
111
  ## Test Interface and Assertions
112
112
 
113
113
  Konacha includes a vendored copy of mocha.js and the [chai](http://chaijs.com/)
114
- assertion libraries.
115
-
116
- By default, it will assume that you want to use Mocha's "BDD" test interface, which
114
+ assertion libraries. It configures Mocha to use the "BDD" test interface, which
117
115
  provides `describe()`, `it()`, `before()`, `after()`, `beforeEach()`, and `afterEach()`.
118
- If you want to use the TDD, Exports, or QUnit interfaces instead, set the `interface`
119
- configuration option in an initializer:
120
-
121
- Konacha.configure do |config|
122
- config.interface = :tdd # Or :exports or :qunit
123
- end if defined?(Konacha)
124
116
 
125
117
  Konacha will make all three of chai's assertion styles available to you: `expect`,
126
118
  `should`, and `assert`. See the chai documentation for the details.
@@ -144,9 +136,6 @@ to the page body and instead append it to this test div:
144
136
  it "... should have been removed before the next starts", ->
145
137
  $('#test h1#added').length.should.equal(0)
146
138
 
147
- Note: this functionality is available only for the "BDD" (default) and "TDD" mocha interfaces,
148
- and not for the "exports" or "QUnit" interfaces.
149
-
150
139
  ## Templates / Fixtures
151
140
 
152
141
  Konacha has no template (a.k.a. HTML fixture) support of its own. Instead, we suggest you use
@@ -5,31 +5,34 @@
5
5
  <title>Konacha Tests</title>
6
6
  <%= stylesheet_link_tag "mocha", :debug => false %>
7
7
  <%= stylesheet_link_tag "konacha", :debug => false %>
8
- <%= javascript_include_tag "jquery", "mocha", "chai", "konacha/#{Konacha.mode}", :debug => false %>
8
+ <%= javascript_include_tag "mocha", "chai", "konacha/#{Konacha.mode}", :debug => false %>
9
9
  <script>
10
- mocha.setup(<%= raw Konacha.interface.to_json %>);
10
+ mocha.setup({ui: "bdd", reporter: Konacha.Reporter});
11
+
12
+ beforeEach(function () {
13
+ var e = document.getElementById('konacha'),
14
+ p = e.parentNode;
15
+
16
+ p.removeChild(e);
17
+
18
+ e = document.createElement("div");
19
+ e.id = "konacha";
20
+
21
+ p.appendChild(e);
22
+ });
23
+
11
24
  var expect = chai.expect,
12
25
  should = chai.should(),
13
26
  assert = chai.assert;
14
27
 
15
28
  window.onload = function () {
16
- mocha.run(Konacha.Reporter);
29
+ mocha.run();
17
30
  };
18
-
19
- <% if Konacha.interface == :bdd %>
20
- beforeEach(function() {
21
- document.getElementById('test').innerHTML = "";
22
- });
23
- <% elsif Konacha.interface == :tdd %>
24
- setup(function() {
25
- document.getElementById('test').innerHTML = "";
26
- });
27
- <% end %>
28
31
  </script>
29
32
  <%= spec_include_tag *@specs %>
30
33
  </head>
31
34
  <body>
32
35
  <div id="mocha"></div>
33
- <div id="test"></div>
36
+ <div id="konacha"></div>
34
37
  </body>
35
38
  </html>
@@ -17,12 +17,12 @@ 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 = "0.10.0"
20
+ gem.version = "1.0.0.rc1"
21
21
 
22
- gem.add_dependency "jquery-rails"
23
22
  gem.add_dependency "rails", "~> 3.1"
24
23
  gem.add_dependency "capybara"
25
24
 
25
+ gem.add_development_dependency "jquery-rails"
26
26
  gem.add_development_dependency "rspec-rails"
27
27
  gem.add_development_dependency "capybara-firebug", "~> 1.1"
28
28
  gem.add_development_dependency "coffee-script"
@@ -0,0 +1,5 @@
1
+ /* Keep #konacha div visible so we can test against element visibility */
2
+ #konacha {
3
+ height: 0 ! important;
4
+ overflow: hidden ! important;
5
+ }
@@ -7,7 +7,7 @@ module Konacha
7
7
  attr_accessor :mode
8
8
 
9
9
  def serve
10
- puts "your tests are here:"
10
+ puts "Your tests are here:"
11
11
  puts " http://localhost:#{port}/"
12
12
  self.mode = :server
13
13
  Konacha::Server.start
@@ -26,7 +26,7 @@ module Konacha
26
26
  yield config
27
27
  end
28
28
 
29
- delegate :port, :spec_dir, :interface, :application, :driver, :to => :config
29
+ delegate :port, :spec_dir, :application, :driver, :to => :config
30
30
 
31
31
  def spec_root
32
32
  File.join(Rails.root, config.spec_dir)
@@ -23,7 +23,6 @@ module Konacha
23
23
 
24
24
  options.spec_dir ||= "spec/javascripts"
25
25
  options.port ||= 3500
26
- options.interface ||= :bdd
27
26
  options.application ||= self.class.application(app)
28
27
  options.driver ||= :selenium
29
28
 
@@ -6,111 +6,19 @@ module Konacha
6
6
  new.run
7
7
  end
8
8
 
9
- class Example
10
- def initialize(row)
11
- @row = row
12
- end
13
-
14
- def passed?
15
- @row['passed']
16
- end
17
-
18
- def failure_message
19
- unless passed?
20
- msg = []
21
- msg << " Failed: #{@row['name']}"
22
- msg << " #{@row['message']}"
23
- msg << " in #{@row['trace']['fileName']}:#{@row['trace']['lineNumber']}" if @row['trace']
24
- msg.join("\n")
25
- end
26
- end
27
- end
28
-
29
- class SpecRunner
30
- attr_reader :runner, :spec
31
-
32
- def initialize(runner, spec)
33
- @runner = runner
34
- @spec = spec
35
- end
36
-
37
- def session
38
- runner.session
39
- end
40
-
41
- def io
42
- runner.io
43
- end
44
-
45
- def run
46
- io.puts dots
47
- io.puts failure_messages
48
- io.puts "\n#{examples.size} examples, #{failed_examples.size} failures"
49
- passed?
50
- end
51
-
52
- def examples
53
- @results ||= begin
54
- session.visit(spec.url)
55
-
56
- previous_results = ""
57
-
58
- session.wait_until(300) do
59
- dots = session.evaluate_script('Konacha.dots')
60
- io.print dots.sub(/^#{Regexp.escape(previous_results)}/, '')
61
- io.flush
62
- previous_results = dots
63
- session.evaluate_script('Konacha.done')
64
- end
65
-
66
- dots = session.evaluate_script('Konacha.dots')
67
- io.print dots.sub(/^#{Regexp.escape(previous_results)}/, '')
68
-
69
- JSON.parse(session.evaluate_script('Konacha.getResults()')).map do |row|
70
- Example.new(row)
71
- end
72
- end
73
- end
74
-
75
- def failed_examples
76
- examples.select { |example| not example.passed? }
77
- end
78
-
79
- def passed?
80
- examples.all? { |example| example.passed? }
81
- end
82
-
83
- def dots
84
- examples; ""
85
- end
86
-
87
- def failure_messages
88
- unless passed?
89
- examples.map { |example| example.failure_message }.compact.join("\n\n")
90
- end
91
- end
92
- end
93
-
94
- attr_reader :suite, :io
9
+ attr_reader :io
95
10
 
96
11
  def initialize(options = {})
97
12
  @io = options[:output] || STDOUT
98
13
  end
99
14
 
100
- def spec_runner(spec)
101
- SpecRunner.new(self, spec)
102
- end
103
-
104
15
  def run
105
16
  before = Time.now
106
17
 
18
+ spec_runners.each { |spec_runner| spec_runner.run } # prints dots
107
19
  io.puts ""
108
- io.puts dots.to_s
109
20
  io.puts ""
110
- if failure_messages
111
- io.puts failure_messages
112
- io.puts ""
113
- end
21
+ failure_messages.each { |msg| io.write("#{msg}\n\n") }
114
22
 
115
23
  seconds = "%.2f" % (Time.now - before)
116
24
  io.puts "Finished in #{seconds} seconds"
@@ -127,27 +35,73 @@ module Konacha
127
35
  end
128
36
 
129
37
  def passed?
130
- spec_runners.all? { |spec_runner| spec_runner.passed? }
131
- end
132
-
133
- def dots
134
- spec_runners.map { |spec_runner| spec_runner.dots }.join
38
+ examples.all? { |example| example.passed? }
135
39
  end
136
40
 
137
41
  def failure_messages
138
- unless passed?
139
- spec_runners.map { |spec_runner| spec_runner.failure_messages }.compact.join("\n\n")
140
- end
42
+ examples.map { |example| example.failure_message }.compact
141
43
  end
142
44
 
143
45
  def session
144
46
  @session ||= Capybara::Session.new(Konacha.driver, Konacha.application)
145
47
  end
146
48
 
147
- protected
148
-
149
49
  def spec_runners
150
50
  @spec_runners ||= Konacha::Spec.all.map { |spec| SpecRunner.new(self, spec) }
151
51
  end
152
52
  end
53
+
54
+ class SpecRunner
55
+ attr_reader :runner, :spec, :examples
56
+
57
+ def initialize(runner, spec)
58
+ @runner = runner
59
+ @spec = spec
60
+ end
61
+
62
+ def session
63
+ runner.session
64
+ end
65
+
66
+ def io
67
+ runner.io
68
+ end
69
+
70
+ def run
71
+ session.visit(spec.url)
72
+
73
+ dots_printed = 0
74
+ begin
75
+ sleep 0.1
76
+ done, dots = session.evaluate_script('[Konacha.done, Konacha.dots]')
77
+ io.write dots[dots_printed..-1]
78
+ io.flush
79
+ dots_printed = dots.length
80
+ end until done
81
+
82
+ @examples = JSON.parse(session.evaluate_script('Konacha.getResults()')).map do |row|
83
+ Example.new(row)
84
+ end
85
+ end
86
+ end
87
+
88
+ class Example
89
+ def initialize(row)
90
+ @row = row
91
+ end
92
+
93
+ def passed?
94
+ @row['passed']
95
+ end
96
+
97
+ def failure_message
98
+ unless passed?
99
+ msg = []
100
+ msg << " Failed: #{@row['name']}"
101
+ msg << " #{@row['message']}"
102
+ msg << " in #{@row['trace']['fileName']}:#{@row['trace']['lineNumber']}" if @row['trace']
103
+ msg.join("\n")
104
+ end
105
+ end
106
+ end
153
107
  end
@@ -1,8 +1,9 @@
1
1
  //= require spec_helper
2
+ //= require jquery
2
3
 
3
4
  describe("templating", function(){
4
5
  it("is built in to Sprockets", function(){
5
- $('#test').html(JST['templates/hello']());
6
- $('#test h1').text().should.equal('Hello Konacha!');
6
+ $('#konacha').html(JST['templates/hello']());
7
+ $('#konacha h1').text().should.equal('Hello Konacha!');
7
8
  });
8
9
  });
@@ -1,10 +1,18 @@
1
- describe "the #test element", ->
1
+ #= require jquery
2
+
3
+ describe "the #konacha element", ->
2
4
  it "can have content added in one test...", ->
3
- $('#test').append('<h1 id="added">New Stuff</h1>')
4
- $('#test h1#added').length.should.equal(1)
5
+ $('#konacha').append('<h1 id="added">New Stuff</h1>')
6
+ $('#konacha h1#added').length.should.equal(1)
7
+
8
+ it "... that is removed before the next starts", ->
9
+ $('#konacha h1#added').length.should.equal(0)
10
+
11
+ it "can have an attribute added in one test...", ->
12
+ $('#konacha').addClass('test')
5
13
 
6
14
  it "... that is removed before the next starts", ->
7
- $('#test h1#added').length.should.equal(0)
15
+ $('#konacha').hasClass('test').should.be.false;
8
16
 
9
17
  it "is visible", ->
10
- $('#test').is(':visible').should.be.true
18
+ $('#konacha').is(':visible').should.be.true
@@ -4,12 +4,6 @@ describe Konacha do
4
4
  describe ".config" do
5
5
  subject { Konacha.config }
6
6
 
7
- describe ".interface" do
8
- it "defaults to :bdd interface" do
9
- subject.interface.should == :bdd
10
- end
11
- end
12
-
13
7
  describe ".spec_dir" do
14
8
  it "defaults to 'spec/javascripts'" do
15
9
  subject.spec_dir.should == "spec/javascripts"
@@ -15,27 +15,12 @@ describe Konacha::Runner do
15
15
  it "prints results to the output" do
16
16
  buffer.rewind
17
17
  results = buffer.read
18
- # "should include" gives us nice multi-line error messages if there is
19
- # more than one failure
20
- results.should include 'examples, 1 failure'
21
18
  # Failure output present?
22
19
  results.should include 'F'
23
20
  results.should include 'expected 4 to equal 5'
24
- # Enough examples run?
25
- results.should match /[1-9][0-9]+ examples, 1 failure/
26
- end
27
- end
28
-
29
- describe "#run_spec" do
30
- let(:spec) { Konacha::Spec.find("failing_spec").first }
31
- before { runner.spec_runner(spec).run }
32
-
33
- it "prints results to the output" do
34
- buffer.rewind
35
- results = buffer.read
36
- results.should include('F')
37
- results.should include("expected 4 to equal 5")
38
- results.should include("1 examples, 1 failures")
21
+ # Summary and dots
22
+ results.should include "#{runner.examples.length} examples, 1 failure"
23
+ results.should match /^[.F]{#{runner.examples.length}}$/
39
24
  end
40
25
  end
41
26
  end