konacha 0.9.0 → 0.9.1
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/.gitignore +1 -0
- data/History.md +14 -0
- data/README.md +6 -21
- data/Vendorfile +5 -0
- data/app/controllers/konacha/specs_controller.rb +4 -15
- data/app/helpers/konacha/specs_helper.rb +11 -0
- data/app/models/konacha/spec.rb +8 -5
- data/app/views/{layouts/konacha → konacha/specs}/specs.html.erb +10 -6
- data/config/routes.rb +2 -2
- data/konacha.gemspec +4 -3
- data/lib/konacha/engine.rb +4 -2
- data/spec/controllers/specs_controller_spec.rb +8 -32
- data/spec/dummy/spec/javascripts/test_element_spec.js.coffee +10 -0
- data/spec/models/spec_spec.rb +25 -13
- data/spec/runner_spec.rb +9 -4
- data/spec/server_spec.rb +6 -0
- data/spec/spec_helper.rb +22 -3
- data/spec/views/specs/specs.html.erb_spec.rb +33 -3
- data/vendor/assets/javascripts/chai.js +221 -86
- data/vendor/assets/javascripts/konacha/runner.js +29 -62
- data/vendor/assets/javascripts/konacha/server.js +3 -0
- data/vendor/assets/javascripts/mocha.js +493 -59
- data/vendor/assets/stylesheets/konacha.css +6 -0
- data/vendor/assets/stylesheets/mocha.css +5 -1
- metadata +49 -32
- data/app/views/konacha/specs/index.html.erb +0 -1
- data/app/views/konacha/specs/show.html.erb +0 -1
- data/spec/dummy/spec/javascripts/transactions_spec.js.coffee +0 -7
- data/spec/views/specs/index.html.erb_spec.rb +0 -12
- data/spec/views/specs/show.html.erb_spec.rb +0 -10
data/.gitignore
CHANGED
data/History.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# master
|
2
|
+
|
3
|
+
# 0.9.1
|
4
|
+
|
5
|
+
* Support foo_spec.coffee files (without .js)
|
6
|
+
* Rename Konacha::Spec#basename to #asset_name
|
7
|
+
* Switch default port to 3500 to avoid collisions with HTTP proxies (like Charles)
|
8
|
+
* Update vendored copies of mocha (0.14.0+) and chai (0.4.2+)
|
9
|
+
* Do not require spec dependencies multiple times (#3)
|
10
|
+
* Support running a subset of specs via a subdirectory path
|
11
|
+
|
12
|
+
# 0.9.0
|
13
|
+
|
14
|
+
* Initial release
|
data/README.md
CHANGED
@@ -6,8 +6,8 @@ assertion library.
|
|
6
6
|
|
7
7
|
[![Konacha][2]][1]
|
8
8
|
|
9
|
-
[1]: http://en.wikipedia.org/wiki/
|
10
|
-
[2]: vendor/assets/images/konacha.jpg
|
9
|
+
[1]: http://en.wikipedia.org/wiki/Konacha
|
10
|
+
[2]: https://github.com/jfirebaugh/konacha/raw/master/vendor/assets/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
|
@@ -16,20 +16,12 @@ the asset pipeline and engines.
|
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
19
|
-
Add konacha to the `:test` and `:development` groups in the Gemfile
|
19
|
+
Add konacha to the `:test` and `:development` groups in the Gemfile and `bundle install`:
|
20
20
|
|
21
21
|
group :test, :development do
|
22
22
|
gem "konacha"
|
23
23
|
end
|
24
24
|
|
25
|
-
And then execute:
|
26
|
-
|
27
|
-
$ bundle
|
28
|
-
|
29
|
-
Or install it yourself as:
|
30
|
-
|
31
|
-
$ gem install konacha
|
32
|
-
|
33
25
|
## Usage
|
34
26
|
|
35
27
|
Create a `spec/javascripts` directory and name the files in it with a `_spec` suffix.
|
@@ -65,8 +57,9 @@ Or, if you prefer CoffeeScript, in `spec/javascripts/array_sum_spec.js.coffee`:
|
|
65
57
|
[1,2,3].sum().should.equal(6)
|
66
58
|
|
67
59
|
The `konacha:server` rake task starts a server for your tests. You can go to the root
|
68
|
-
page to run all specs (e.g. `http://localhost:
|
69
|
-
spec file (e.g. `http://localhost:
|
60
|
+
page to run all specs (e.g. `http://localhost:3500/`), a sub page to run an individual
|
61
|
+
spec file (e.g. `http://localhost:3500/array_sum_spec`), or a path to a subdirectory to
|
62
|
+
run a subset of specs (e.g. `http://localhost:3500/models`).
|
70
63
|
|
71
64
|
Alternatively, you can run the specs headlessly with the `konacha:ci` task.
|
72
65
|
|
@@ -180,14 +173,6 @@ And your spec:
|
|
180
173
|
});
|
181
174
|
});
|
182
175
|
|
183
|
-
## Contributing
|
184
|
-
|
185
|
-
1. Fork it
|
186
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
187
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
188
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
189
|
-
5. Create new Pull Request
|
190
|
-
|
191
176
|
## License
|
192
177
|
|
193
178
|
Copyright (c) 2012 John Firebaugh
|
data/Vendorfile
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
folder 'vendor/assets' do
|
2
|
+
file 'javascripts/chai.js', 'https://raw.github.com/logicalparadox/chai/master/chai.js'
|
3
|
+
file 'javascripts/mocha.js', 'https://raw.github.com/visionmedia/mocha/master/mocha.js'
|
4
|
+
file 'stylesheets/mocha.css', 'https://raw.github.com/visionmedia/mocha/master/mocha.css'
|
5
|
+
end
|
@@ -1,22 +1,11 @@
|
|
1
1
|
module Konacha
|
2
2
|
class SpecsController < ActionController::Base
|
3
|
-
|
4
|
-
|
5
|
-
def set_interface
|
6
|
-
@interface = Konacha.interface
|
7
|
-
end
|
8
|
-
|
9
|
-
def set_mode
|
10
|
-
@mode = Konacha.mode
|
11
|
-
end
|
12
|
-
|
13
|
-
def index
|
14
|
-
@specs = Konacha::Spec.all
|
3
|
+
rescue_from Konacha::Spec::NotFound do
|
4
|
+
render :text => "Not found", :status => 404
|
15
5
|
end
|
16
6
|
|
17
|
-
def
|
18
|
-
@
|
19
|
-
@spec or render :text => "Not Found", :status => 404
|
7
|
+
def specs
|
8
|
+
@specs = Konacha::Spec.find(params[:path] || "")
|
20
9
|
end
|
21
10
|
end
|
22
11
|
end
|
data/app/models/konacha/spec.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module Konacha
|
2
2
|
class Spec
|
3
|
+
class NotFound < StandardError
|
4
|
+
end
|
5
|
+
|
3
6
|
def self.all
|
4
7
|
Konacha.spec_paths.map { |path| new(path) }
|
5
8
|
end
|
6
9
|
|
7
|
-
def self.find(
|
8
|
-
all.
|
10
|
+
def self.find(path)
|
11
|
+
all.select { |s| s.path.starts_with?(path) }.presence or raise NotFound
|
9
12
|
end
|
10
13
|
|
11
14
|
attr_accessor :path
|
@@ -15,11 +18,11 @@ module Konacha
|
|
15
18
|
end
|
16
19
|
|
17
20
|
def url
|
18
|
-
"/#{
|
21
|
+
"/#{asset_name}"
|
19
22
|
end
|
20
23
|
|
21
|
-
def
|
22
|
-
path
|
24
|
+
def asset_name
|
25
|
+
path.sub(/(\.js|\.coffee).*/, '')
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -4,25 +4,29 @@
|
|
4
4
|
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
5
5
|
<title>Mocha Tests</title>
|
6
6
|
<%= stylesheet_link_tag "mocha" %>
|
7
|
-
<%=
|
7
|
+
<%= stylesheet_link_tag "konacha" %>
|
8
|
+
<%= javascript_include_tag "jquery", "mocha", "chai", "konacha/#{Konacha.mode}" %>
|
8
9
|
<script>
|
9
|
-
mocha.setup(<%= raw
|
10
|
+
mocha.setup(<%= raw Konacha.interface.to_json %>);
|
10
11
|
var expect = chai.expect,
|
11
12
|
should = chai.should(),
|
12
13
|
assert = chai.assert;
|
13
|
-
window.onload = mocha.run;
|
14
14
|
|
15
|
-
|
15
|
+
window.onload = function () {
|
16
|
+
mocha.run(Konacha.Reporter);
|
17
|
+
};
|
18
|
+
|
19
|
+
<% if Konacha.interface == :bdd %>
|
16
20
|
beforeEach(function() {
|
17
21
|
document.getElementById('test').innerHTML = "";
|
18
22
|
});
|
19
|
-
<% elsif
|
23
|
+
<% elsif Konacha.interface == :tdd %>
|
20
24
|
setup(function() {
|
21
25
|
document.getElementById('test').innerHTML = "";
|
22
26
|
});
|
23
27
|
<% end %>
|
24
28
|
</script>
|
25
|
-
<%=
|
29
|
+
<%= spec_include_tag *@specs %>
|
26
30
|
</head>
|
27
31
|
<body>
|
28
32
|
<div id="mocha"></div>
|
data/config/routes.rb
CHANGED
data/konacha.gemspec
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.authors = ["John Firebaugh"]
|
5
5
|
gem.email = ["john.firebaugh@gmail.com"]
|
6
|
-
gem.
|
7
|
-
gem.
|
6
|
+
gem.summary = %q{Unit-test your Rails JavaScript with the mocha test framework and chai assertion library}
|
7
|
+
gem.description = %q{Konacha is a Rails engine that allows you to test your JavaScript with the
|
8
8
|
mocha test framework and chai assertion library.
|
9
9
|
|
10
10
|
It is similar to Jasmine and Evergreen, but does not attempt to be framework
|
@@ -17,7 +17,7 @@ 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.9.
|
20
|
+
gem.version = "0.9.1"
|
21
21
|
|
22
22
|
gem.add_dependency "jquery-rails"
|
23
23
|
gem.add_dependency "rails", "~> 3.1"
|
@@ -27,4 +27,5 @@ the asset pipeline and engines.}
|
|
27
27
|
gem.add_development_dependency "capybara-firebug", "~> 1.1"
|
28
28
|
gem.add_development_dependency "coffee-script"
|
29
29
|
gem.add_development_dependency "ejs"
|
30
|
+
gem.add_development_dependency "vendorer"
|
30
31
|
end
|
data/lib/konacha/engine.rb
CHANGED
@@ -8,7 +8,9 @@ module Konacha
|
|
8
8
|
run app.assets
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
map "/" do
|
12
|
+
run Konacha::Engine
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -20,7 +22,7 @@ module Konacha
|
|
20
22
|
options = app.config.konacha
|
21
23
|
|
22
24
|
options.spec_dir ||= "spec/javascripts"
|
23
|
-
options.port ||=
|
25
|
+
options.port ||= 3500
|
24
26
|
options.interface ||= :bdd
|
25
27
|
options.application ||= self.class.application(app)
|
26
28
|
options.driver ||= :selenium
|
@@ -5,40 +5,16 @@ describe Konacha::SpecsController do
|
|
5
5
|
@routes = Konacha::Engine.routes
|
6
6
|
end
|
7
7
|
|
8
|
-
describe "#
|
9
|
-
it "assigns
|
10
|
-
Konacha.should_receive(:
|
11
|
-
|
12
|
-
assigns[:
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#set_mode" do
|
17
|
-
it "assigns Konacha.mode to @mode" do
|
18
|
-
Konacha.should_receive(:mode) { :runner }
|
19
|
-
subject.set_mode
|
20
|
-
assigns[:mode].should == :runner
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#index" do
|
25
|
-
it "assigns Konacha::Spec.all to @specs" do
|
26
|
-
Konacha::Spec.should_receive(:all) { :all }
|
27
|
-
get :index
|
28
|
-
assigns[:specs].should == :all
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#show" do
|
33
|
-
it "finds the spec with the given basename and assigns it to @spec" do
|
34
|
-
Konacha::Spec.should_receive(:find).with("array_spec") { :spec }
|
35
|
-
get :show, :spec => "array_spec"
|
36
|
-
assigns[:spec].should == :spec
|
8
|
+
describe "#specs" do
|
9
|
+
it "assigns the result of Spec.find to @specs" do
|
10
|
+
Konacha::Spec.should_receive(:find).with("spec_path") { :spec }
|
11
|
+
get :specs, :path => "spec_path"
|
12
|
+
assigns[:specs].should == :spec
|
37
13
|
end
|
38
14
|
|
39
|
-
it "404s if there is no
|
40
|
-
Konacha::Spec.should_receive(:find).with("array_spec") {
|
41
|
-
get :
|
15
|
+
it "404s if there is no match for the given path" do
|
16
|
+
Konacha::Spec.should_receive(:find).with("array_spec") { raise Konacha::Spec::NotFound }
|
17
|
+
get :specs, :path => "array_spec"
|
42
18
|
response.status.should == 404
|
43
19
|
response.should_not render_template("konacha/specs/show")
|
44
20
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
describe "the #test element", ->
|
2
|
+
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
|
+
|
6
|
+
it "... that is removed before the next starts", ->
|
7
|
+
$('#test h1#added').length.should.equal(0)
|
8
|
+
|
9
|
+
it "is visible", ->
|
10
|
+
$('#test').is(':visible').should.be.true
|
data/spec/models/spec_spec.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Konacha::Spec do
|
4
|
-
describe "#
|
5
|
-
it "is the
|
6
|
-
described_class.new("array_spec.js").
|
4
|
+
describe "#asset_name" do
|
5
|
+
it "is the asset_name of the path" do
|
6
|
+
described_class.new("array_spec.js").asset_name.should == "array_spec"
|
7
|
+
described_class.new("array_spec.coffee").asset_name.should == "array_spec"
|
7
8
|
end
|
8
9
|
|
9
10
|
it "ignores multiple extensions" do
|
10
|
-
described_class.new("array_spec.js.coffee").
|
11
|
+
described_class.new("array_spec.js.coffee").asset_name.should == "array_spec"
|
11
12
|
end
|
12
13
|
|
13
14
|
it "includes relative path" do
|
14
|
-
described_class.new("subdirectory/array_spec.js").
|
15
|
+
described_class.new("subdirectory/array_spec.js").asset_name.should == "subdirectory/array_spec"
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -30,16 +31,27 @@ describe Konacha::Spec do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
describe ".find" do
|
33
|
-
it "returns
|
34
|
-
all = [
|
35
|
-
|
36
|
-
described_class.
|
37
|
-
described_class.find("b_spec").should == all[1]
|
34
|
+
it "returns all Specs if given an empty path" do
|
35
|
+
all = ["a_spec.js", "b_spec.js"]
|
36
|
+
Konacha.should_receive(:spec_paths) { all }
|
37
|
+
described_class.find("").map(&:path).should == all
|
38
38
|
end
|
39
39
|
|
40
|
-
it "returns
|
41
|
-
|
42
|
-
|
40
|
+
it "returns an array containing the Spec with the given asset_name" do
|
41
|
+
all = ["a_spec.js", "b_spec.js"]
|
42
|
+
Konacha.should_receive(:spec_paths) { all }
|
43
|
+
described_class.find("b_spec").map(&:path).should == [all[1]]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns Specs that are children of the given path" do
|
47
|
+
all = ["a/a_spec_1.js", "a/a_spec_2.js", "b/b_spec.js"]
|
48
|
+
Konacha.should_receive(:spec_paths) { all }
|
49
|
+
described_class.find("a").map(&:path).should == all[0..1]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises NotFound if no Specs match" do
|
53
|
+
Konacha.should_receive(:spec_paths) { [] }
|
54
|
+
expect { described_class.find("b_spec") }.to raise_error(Konacha::Spec::NotFound)
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -15,14 +15,19 @@ describe Konacha::Runner do
|
|
15
15
|
it "prints results to the output" do
|
16
16
|
buffer.rewind
|
17
17
|
results = buffer.read
|
18
|
-
|
19
|
-
|
20
|
-
results.should include
|
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
|
+
# Failure output present?
|
22
|
+
results.should include 'F'
|
23
|
+
results.should include 'expected 4 to equal 5'
|
24
|
+
# Enough examples run?
|
25
|
+
results.should match /[1-9][0-9]+ examples, 1 failure/
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
29
|
describe "#run_spec" do
|
25
|
-
let(:spec) { Konacha::Spec.find("failing_spec") }
|
30
|
+
let(:spec) { Konacha::Spec.find("failing_spec").first }
|
26
31
|
before { runner.spec_runner(spec).run }
|
27
32
|
|
28
33
|
it "prints results to the output" do
|
data/spec/server_spec.rb
CHANGED
@@ -33,6 +33,12 @@ describe Konacha::Server, :type => :request do
|
|
33
33
|
page.should have_css(".test.pass")
|
34
34
|
end
|
35
35
|
|
36
|
+
it "serves a subdirectory of specs" do
|
37
|
+
visit "/subdirectory"
|
38
|
+
page.should have_content("spec in subdirectory")
|
39
|
+
page.should have_css(".test.pass")
|
40
|
+
end
|
41
|
+
|
36
42
|
it "supports spec helpers" do
|
37
43
|
visit "/spec_helper_spec"
|
38
44
|
page.should have_content("two_plus_two")
|
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,9 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
4
4
|
require "rspec/rails"
|
5
5
|
require "rspec/autorun"
|
6
6
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
7
|
+
# Preload to avoid occasional tilt warnings about thread safety
|
8
|
+
require "coffee_script"
|
9
|
+
require "ejs"
|
10
10
|
|
11
11
|
require "capybara/rails"
|
12
12
|
require "capybara/firebug"
|
@@ -16,3 +16,22 @@ Capybara.configure do |config|
|
|
16
16
|
config.default_driver = :selenium_with_firebug
|
17
17
|
config.app = Konacha.application
|
18
18
|
end
|
19
|
+
|
20
|
+
module SpecDoubleHelpers
|
21
|
+
def asset_double(asset_name, dependencies = [])
|
22
|
+
asset = double("asset called '#{asset_name}'")
|
23
|
+
asset.stub(:to_a).and_return([dependencies, asset].flatten)
|
24
|
+
asset.stub(:logical_path).and_return(asset_name)
|
25
|
+
view.asset_paths.stub(:asset_for).with(asset_name, "js").and_return(asset)
|
26
|
+
asset
|
27
|
+
end
|
28
|
+
|
29
|
+
def spec_double(asset_name, dependencies = [])
|
30
|
+
asset_double(asset_name, dependencies)
|
31
|
+
double("spec called '#{asset_name}'", :asset_name => asset_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include SpecDoubleHelpers, :type => :view
|
37
|
+
end
|
@@ -1,15 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "konacha/specs/specs" do
|
4
4
|
it "sets up the specified interface" do
|
5
|
-
|
5
|
+
Konacha.should_receive(:interface).any_number_of_times { :tdd }
|
6
6
|
render
|
7
7
|
rendered.should include('mocha.setup("tdd")')
|
8
8
|
end
|
9
9
|
|
10
10
|
it "includes konacha JS for given mode" do
|
11
|
-
|
11
|
+
Konacha.should_receive(:mode).any_number_of_times { :runner }
|
12
12
|
render
|
13
13
|
rendered.should have_css("script[src='/assets/konacha/runner.js']")
|
14
14
|
end
|
15
|
+
|
16
|
+
let(:dependency) { asset_double("dependency") }
|
17
|
+
|
18
|
+
it "renders a script tag for each spec in @specs" do
|
19
|
+
assign(:specs, [spec_double("a_spec"),
|
20
|
+
spec_double("b_spec")])
|
21
|
+
|
22
|
+
render
|
23
|
+
|
24
|
+
rendered.should have_selector("script[src='/assets/a_spec.js?body=1']")
|
25
|
+
rendered.should have_selector("script[src='/assets/b_spec.js?body=1']")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "renders a script tag for a spec's dependencies" do
|
29
|
+
assign(:specs, [spec_double("spec", [dependency])])
|
30
|
+
|
31
|
+
render
|
32
|
+
|
33
|
+
rendered.should have_selector("script[src='/assets/dependency.js?body=1']")
|
34
|
+
rendered.should have_selector("script[src='/assets/spec.js?body=1']")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "renders only one script tag for common dependencies" do
|
38
|
+
assign(:specs, [spec_double("a_spec", [dependency]),
|
39
|
+
spec_double("b_spec", [dependency])])
|
40
|
+
|
41
|
+
render
|
42
|
+
|
43
|
+
rendered.should have_selector("script[src='/assets/dependency.js?body=1']", :count => 1)
|
44
|
+
end
|
15
45
|
end
|