konacha 2.0.0.beta3 → 2.0.0
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/app/assets/javascripts/konacha/iframe.js +1 -0
- data/app/assets/javascripts/konacha/parent.js +4 -0
- data/app/assets/javascripts/konacha/runner.js +3 -1
- data/app/controllers/konacha/specs_controller.rb +2 -2
- data/app/models/konacha/spec.rb +8 -10
- data/app/views/konacha/specs/iframe.html.erb +2 -2
- data/app/views/konacha/specs/parent.html.erb +1 -1
- data/config/routes.rb +2 -3
- data/konacha.gemspec +1 -1
- data/lib/konacha/reporter.rb +5 -1
- data/lib/konacha/runner.rb +15 -20
- data/spec/controllers/specs_controller_spec.rb +6 -6
- data/spec/models/spec_spec.rb +17 -12
- data/spec/reporter/metadata_spec.rb +1 -1
- data/spec/reporter_spec.rb +12 -1
- data/spec/runner_spec.rb +5 -0
- data/spec/views/specs/iframe.html.erb_spec.rb +15 -16
- metadata +9 -6
@@ -11,6 +11,7 @@ window.mocha = Object.create(parent.mocha);
|
|
11
11
|
// In order to isolate top-level before/beforeEach hooks,
|
12
12
|
// the specs in each iframe are wrapped in an anonymous suite.
|
13
13
|
mocha.suite = Mocha.Suite.create(mocha.suite);
|
14
|
+
mocha.suite.path = document.documentElement.getAttribute("data-path");
|
14
15
|
|
15
16
|
// Override mocha.ui so that the pre-require event is emitted
|
16
17
|
// with the iframe's `window` reference, rather than the parent's.
|
@@ -35,7 +35,9 @@ mocha.reporter(function(runner) {
|
|
35
35
|
Mocha.reporters.Base.call(this, runner);
|
36
36
|
|
37
37
|
runner.on('start', function() {
|
38
|
-
Konacha.events = [
|
38
|
+
Konacha.events = [
|
39
|
+
{event:'start', testCount:runner.total, data:{}}
|
40
|
+
];
|
39
41
|
});
|
40
42
|
|
41
43
|
runner.on('suite', function(suite) {
|
@@ -5,11 +5,11 @@ module Konacha
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def parent
|
8
|
-
@specs = Konacha::Spec.
|
8
|
+
@specs = Konacha::Spec.all(params[:path])
|
9
9
|
end
|
10
10
|
|
11
11
|
def iframe
|
12
|
-
@
|
12
|
+
@spec = Konacha::Spec.find_by_name(params[:name])
|
13
13
|
@stylesheets = Konacha::Engine.config.konacha.stylesheets
|
14
14
|
end
|
15
15
|
end
|
data/app/models/konacha/spec.rb
CHANGED
@@ -3,16 +3,18 @@ module Konacha
|
|
3
3
|
class NotFound < StandardError
|
4
4
|
end
|
5
5
|
|
6
|
-
def self.all
|
6
|
+
def self.all(path = nil)
|
7
7
|
paths = Konacha.spec_paths
|
8
|
-
if ENV["SPEC"]
|
9
|
-
|
8
|
+
paths = ENV["SPEC"].split(",") if ENV["SPEC"]
|
9
|
+
paths = paths.map { |p| new(p) }
|
10
|
+
if path.present?
|
11
|
+
paths = paths.select { |s| s.path.starts_with?(path) }.presence or raise NotFound
|
10
12
|
end
|
11
|
-
paths
|
13
|
+
paths
|
12
14
|
end
|
13
15
|
|
14
|
-
def self.
|
15
|
-
all.
|
16
|
+
def self.find_by_name(name)
|
17
|
+
all.find { |s| s.asset_name == name } or raise NotFound
|
16
18
|
end
|
17
19
|
|
18
20
|
attr_accessor :path
|
@@ -21,10 +23,6 @@ module Konacha
|
|
21
23
|
@path = path
|
22
24
|
end
|
23
25
|
|
24
|
-
def url
|
25
|
-
"/iframe/#{asset_name}"
|
26
|
-
end
|
27
|
-
|
28
26
|
def asset_name
|
29
27
|
path.sub(/(\.js|\.coffee).*/, '')
|
30
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<!doctype html>
|
2
|
-
<html>
|
2
|
+
<html data-path="<%= @spec.path %>">
|
3
3
|
<head>
|
4
4
|
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
5
5
|
<title>Konacha Tests</title>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
<%= javascript_include_tag "chai", "konacha/iframe", :debug => false %>
|
13
13
|
|
14
|
-
<%= spec_include_tag
|
14
|
+
<%= spec_include_tag @spec %>
|
15
15
|
</head>
|
16
16
|
<body>
|
17
17
|
</body>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
</head>
|
10
10
|
<body>
|
11
11
|
<% @specs.each do |spec| %>
|
12
|
-
<%= content_tag :iframe,
|
12
|
+
<%= content_tag :iframe, "", :src => "/iframe/#{spec.asset_name}", :class => "test-context", "data-path" => spec.path %>
|
13
13
|
<% end %>
|
14
14
|
<div id="mocha"></div>
|
15
15
|
</body>
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
Konacha::Engine.routes.draw do
|
2
|
-
match '/iframe'
|
3
|
-
match '/
|
4
|
-
match '/' => 'specs#parent', :as => 'parent'
|
2
|
+
match '/iframe/*name' => 'specs#iframe'
|
3
|
+
match '/' => 'specs#parent'
|
5
4
|
match '*path' => 'specs#parent'
|
6
5
|
end
|
data/konacha.gemspec
CHANGED
@@ -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 = "2.0.0
|
20
|
+
gem.version = "2.0.0"
|
21
21
|
|
22
22
|
gem.add_dependency "railties", "~> 3.1"
|
23
23
|
gem.add_dependency "actionpack", "~> 3.1"
|
data/lib/konacha/reporter.rb
CHANGED
@@ -53,7 +53,11 @@ module Konacha
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def process_mocha_event(event)
|
56
|
-
if event['
|
56
|
+
if event['event'] == 'start'
|
57
|
+
start(event['testCount'])
|
58
|
+
elsif event['event'] == 'end'
|
59
|
+
finish
|
60
|
+
elsif event['type']
|
57
61
|
object = update_or_create_object(event['data'], event['type'])
|
58
62
|
process_event EVENT_CONVERSIONS[event['event']], object
|
59
63
|
end
|
data/lib/konacha/runner.rb
CHANGED
@@ -13,31 +13,26 @@ module Konacha
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
16
|
-
|
16
|
+
session.visit('/')
|
17
17
|
|
18
|
+
events_consumed = 0
|
19
|
+
done = false
|
18
20
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
events = JSON.parse(session.evaluate_script('Konacha.getEvents()'))
|
26
|
-
if events
|
27
|
-
events[events_consumed..-1].each do |event|
|
28
|
-
done = true if event['event'] == 'end'
|
29
|
-
reporter.process_mocha_event(event)
|
30
|
-
end
|
31
|
-
|
32
|
-
events_consumed = events.length
|
21
|
+
sleep 0.1
|
22
|
+
events = JSON.parse(session.evaluate_script('Konacha.getEvents()'))
|
23
|
+
if events
|
24
|
+
events[events_consumed..-1].each do |event|
|
25
|
+
done = true if event['event'] == 'end'
|
26
|
+
reporter.process_mocha_event(event)
|
33
27
|
end
|
34
|
-
end until done
|
35
|
-
rescue => e
|
36
|
-
raise e, "Error communicating with browser process: #{e}", e.backtrace
|
37
|
-
end
|
38
28
|
|
39
|
-
|
29
|
+
events_consumed = events.length
|
30
|
+
end
|
31
|
+
end until done
|
32
|
+
|
40
33
|
reporter.passed?
|
34
|
+
rescue => e
|
35
|
+
raise e, "Error communicating with browser process: #{e}", e.backtrace
|
41
36
|
end
|
42
37
|
|
43
38
|
def session
|
@@ -6,15 +6,15 @@ describe Konacha::SpecsController do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "#iframe" do
|
9
|
-
it "assigns the result of Spec.
|
10
|
-
Konacha::Spec.should_receive(:
|
11
|
-
get :iframe, :
|
12
|
-
assigns[:
|
9
|
+
it "assigns the result of Spec.find_by_name to @spec" do
|
10
|
+
Konacha::Spec.should_receive(:find_by_name).with("spec_name") { :spec }
|
11
|
+
get :iframe, :name => "spec_name"
|
12
|
+
assigns[:spec].should == :spec
|
13
13
|
end
|
14
14
|
|
15
15
|
it "404s if there is no match for the given path" do
|
16
|
-
Konacha::Spec.should_receive(:
|
17
|
-
get :iframe, :
|
16
|
+
Konacha::Spec.should_receive(:find_by_name).with("array_spec") { raise Konacha::Spec::NotFound }
|
17
|
+
get :iframe, :name => "array_spec"
|
18
18
|
response.status.should == 404
|
19
19
|
response.should_not render_template("konacha/specs/iframe")
|
20
20
|
end
|
data/spec/models/spec_spec.rb
CHANGED
@@ -16,12 +16,6 @@ describe Konacha::Spec do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe "#url" do
|
20
|
-
it "returns a URL path" do
|
21
|
-
described_class.new("array_spec.js").url.should include "array_spec"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
19
|
describe ".all" do
|
26
20
|
it "returns an array of specs" do
|
27
21
|
Konacha.should_receive(:spec_paths) { ["a_spec.js", "b_spec.js"] }
|
@@ -37,30 +31,41 @@ describe Konacha::Spec do
|
|
37
31
|
paths =~ %w{foo_spec bar_spec baz_spec}
|
38
32
|
ENV["SPEC"] = nil
|
39
33
|
end
|
40
|
-
end
|
41
34
|
|
42
|
-
describe ".find" do
|
43
35
|
it "returns all Specs if given an empty path" do
|
44
36
|
all = ["a_spec.js", "b_spec.js"]
|
45
37
|
Konacha.should_receive(:spec_paths) { all }
|
46
|
-
described_class.
|
38
|
+
described_class.all("").map(&:path).should == all
|
47
39
|
end
|
48
40
|
|
49
41
|
it "returns an array containing the Spec with the given asset_name" do
|
50
42
|
all = ["a_spec.js", "b_spec.js"]
|
51
43
|
Konacha.should_receive(:spec_paths) { all }
|
52
|
-
described_class.
|
44
|
+
described_class.all("b_spec").map(&:path).should == [all[1]]
|
53
45
|
end
|
54
46
|
|
55
47
|
it "returns Specs that are children of the given path" do
|
56
48
|
all = ["a/a_spec_1.js", "a/a_spec_2.js", "b/b_spec.js"]
|
57
49
|
Konacha.should_receive(:spec_paths) { all }
|
58
|
-
described_class.
|
50
|
+
described_class.all("a").map(&:path).should == all[0..1]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises NotFound if no Specs match" do
|
54
|
+
Konacha.should_receive(:spec_paths) { [] }
|
55
|
+
expect { described_class.all("b_spec") }.to raise_error(Konacha::Spec::NotFound)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".find_by_name" do
|
60
|
+
it "returns the spec with the given asset name" do
|
61
|
+
all = ["a_spec.js", "b_spec.js"]
|
62
|
+
Konacha.should_receive(:spec_paths) { all }
|
63
|
+
described_class.find_by_name("a_spec").path.should == "a_spec.js"
|
59
64
|
end
|
60
65
|
|
61
66
|
it "raises NotFound if no Specs match" do
|
62
67
|
Konacha.should_receive(:spec_paths) { [] }
|
63
|
-
expect { described_class.
|
68
|
+
expect { described_class.find_by_name("b_spec") }.to raise_error(Konacha::Spec::NotFound)
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
@@ -37,7 +37,7 @@ describe Konacha::Reporter::Metadata do
|
|
37
37
|
|
38
38
|
describe "#execution_result" do
|
39
39
|
it "returns a hash with execution details" do
|
40
|
-
subject.execution_result.keys.sort.should == [:exception, :finished_at, :run_time, :started_at, :status]
|
40
|
+
subject.execution_result.keys.map(&:to_s).sort.should == [:exception, :finished_at, :run_time, :started_at, :status].map(&:to_s)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
data/spec/reporter_spec.rb
CHANGED
@@ -47,8 +47,19 @@ describe Konacha::Reporter do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "#process_mocha_event" do
|
50
|
+
before { subject.stub(:process_event) }
|
51
|
+
|
52
|
+
it "calls #start if passed the start event" do
|
53
|
+
subject.should_receive(:start).with(4)
|
54
|
+
subject.process_mocha_event({'event' => 'start', 'testCount' => 4})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "calls #finish if passed the end event" do
|
58
|
+
subject.should_receive(:finish)
|
59
|
+
subject.process_mocha_event({'event' => 'end'})
|
60
|
+
end
|
61
|
+
|
50
62
|
it "creates the object" do
|
51
|
-
subject.stub(:process_event)
|
52
63
|
subject.should_receive(:update_or_create_object).with('data', 'type')
|
53
64
|
subject.process_mocha_event({'data' => 'data', 'type' => 'type'})
|
54
65
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -86,13 +86,18 @@ describe Konacha::Runner do
|
|
86
86
|
'status' => 'pending'}}
|
87
87
|
end
|
88
88
|
|
89
|
+
let(:start) { {'event' => 'start', 'testCount' => kind_of(Integer), 'data' => {} } }
|
90
|
+
let(:end_event) { {'event' => 'end', 'data' => {} } }
|
91
|
+
|
89
92
|
it "passes along the right events" do
|
93
|
+
subject.reporter.should_receive(:process_mocha_event).with(start)
|
90
94
|
subject.reporter.should_receive(:process_mocha_event).with(suite)
|
91
95
|
subject.reporter.should_receive(:process_mocha_event).with(suite_end)
|
92
96
|
subject.reporter.should_receive(:process_mocha_event).with(test)
|
93
97
|
subject.reporter.should_receive(:process_mocha_event).with(failure)
|
94
98
|
subject.reporter.should_receive(:process_mocha_event).with(pass)
|
95
99
|
subject.reporter.should_receive(:process_mocha_event).with(pending)
|
100
|
+
subject.reporter.should_receive(:process_mocha_event).with(end_event)
|
96
101
|
subject.reporter.should_receive(:process_mocha_event).any_number_of_times
|
97
102
|
subject.run
|
98
103
|
end
|
@@ -15,23 +15,21 @@ describe "konacha/specs/iframe" do
|
|
15
15
|
|
16
16
|
def spec_double(asset_name, dependencies = [])
|
17
17
|
asset_double(asset_name, dependencies)
|
18
|
-
double("spec called '#{asset_name}'", :asset_name => asset_name)
|
18
|
+
double("spec called '#{asset_name}'", :asset_name => asset_name, :path => "#{asset_name}.js")
|
19
19
|
end
|
20
20
|
|
21
21
|
let(:dependency) { asset_double("dependency") }
|
22
22
|
|
23
|
-
it "renders a script tag for
|
24
|
-
assign(:
|
25
|
-
spec_double("b_spec")])
|
23
|
+
it "renders a script tag for @spec" do
|
24
|
+
assign(:spec, spec_double("a_spec"))
|
26
25
|
|
27
26
|
render
|
28
27
|
|
29
28
|
rendered.should have_selector("script[src='/assets/a_spec.js?body=1']")
|
30
|
-
rendered.should have_selector("script[src='/assets/b_spec.js?body=1']")
|
31
29
|
end
|
32
30
|
|
33
31
|
it "renders a script tag for a spec's dependencies" do
|
34
|
-
assign(:
|
32
|
+
assign(:spec, spec_double("spec", [dependency]))
|
35
33
|
|
36
34
|
render
|
37
35
|
|
@@ -39,20 +37,11 @@ describe "konacha/specs/iframe" do
|
|
39
37
|
rendered.should have_selector("script[src='/assets/spec.js?body=1']")
|
40
38
|
end
|
41
39
|
|
42
|
-
it "renders only one script tag for common dependencies" do
|
43
|
-
assign(:specs, [spec_double("a_spec", [dependency]),
|
44
|
-
spec_double("b_spec", [dependency])])
|
45
|
-
|
46
|
-
render
|
47
|
-
|
48
|
-
rendered.should have_selector("script[src='/assets/dependency.js?body=1']", :count => 1)
|
49
|
-
end
|
50
|
-
|
51
40
|
it "renders only one script tag for dependencies of dependencies" do
|
52
41
|
dependency_a = asset_double("dependency_a")
|
53
42
|
dependency_b = asset_double("dependency_b", [dependency_a])
|
54
43
|
|
55
|
-
assign(:
|
44
|
+
assign(:spec, spec_double("a_spec", [dependency_a, dependency_b]))
|
56
45
|
|
57
46
|
render
|
58
47
|
|
@@ -61,11 +50,21 @@ describe "konacha/specs/iframe" do
|
|
61
50
|
end
|
62
51
|
|
63
52
|
it "render the stylesheets" do
|
53
|
+
assign(:spec, spec_double("a_spec"))
|
64
54
|
assign(:stylesheets, %w(foo bar))
|
55
|
+
assign(:specs, [])
|
65
56
|
|
66
57
|
render
|
67
58
|
|
68
59
|
rendered.should have_selector("link[href='/assets/foo.css']")
|
69
60
|
rendered.should have_selector("link[href='/assets/bar.css']")
|
70
61
|
end
|
62
|
+
|
63
|
+
it "includes a path data attribute" do
|
64
|
+
assign(:spec, spec_double("a_spec"))
|
65
|
+
|
66
|
+
render
|
67
|
+
|
68
|
+
rendered.should have_selector("[data-path='a_spec.js']")
|
69
|
+
end
|
71
70
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: konacha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John Firebaugh
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -293,13 +293,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
293
|
version: '0'
|
294
294
|
segments:
|
295
295
|
- 0
|
296
|
-
hash:
|
296
|
+
hash: 3302802791356111510
|
297
297
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
298
|
none: false
|
299
299
|
requirements:
|
300
|
-
- - ! '
|
300
|
+
- - ! '>='
|
301
301
|
- !ruby/object:Gem::Version
|
302
|
-
version:
|
302
|
+
version: '0'
|
303
|
+
segments:
|
304
|
+
- 0
|
305
|
+
hash: 3302802791356111510
|
303
306
|
requirements: []
|
304
307
|
rubyforge_project:
|
305
308
|
rubygems_version: 1.8.24
|