jspec_runner 0.1.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/rails/init.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.parent + 'lib/jspec_runner'
3
+
4
+ class ActionController::TestCase
5
+ include JSpecRunner::Extensions
6
+ # this should be loaded by include 'holygrail', but it doesn't seem to work for testing
7
+ include HolyGrail::Extensions
8
+ end
9
+ class ActionController::IntegrationTest
10
+ include JSpecRunner::Extensions
11
+ # this should be loaded by include 'holygrail', but it doesn't seem to work for testing
12
+ include HolyGrail::Extensions
13
+ end
@@ -0,0 +1,19 @@
1
+
2
+ # uncomment and call with `$ jspec example `
3
+
4
+ # command :example do |c|
5
+ # c.syntax = 'jspec example [options]'
6
+ # c.description = 'Just an example command'
7
+ # c.option '-f', '--foo string', 'Does some foo with <string>'
8
+ # c.option '-b', '--bar [string]', 'Does some bar with [string]'
9
+ # c.example 'Do some foo', 'jspec example --foo bar'
10
+ # c.example 'Do some bar', 'jspec example --bar'
11
+ # c.when_called do |args, options|
12
+ # p args
13
+ # p options.__hash__
14
+ # # options.foo
15
+ # # options.bar
16
+ # # options.__hash__[:foo]
17
+ # # options.__hash__[:bar]
18
+ # end
19
+ # end
@@ -0,0 +1,23 @@
1
+ <html>
2
+ <head>
3
+ <link type="text/css" rel="stylesheet" href="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.css" />
4
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.js"></script>
5
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.xhr.js"></script>
6
+ <script type="text/javascript" src="../public/javascripts/jquery-1.4.2.min.js"></script>
7
+ <script type="text/javascript" src="../public/javascripts/change_body.js"></script>
8
+ <script src="unit/spec.helper.js"></script>
9
+ <script>
10
+ function runSuites() {
11
+ JSpec
12
+ .exec('unit/spec.failure.js')
13
+ .run({ fixturePath: 'fixtures' })
14
+ .report()
15
+ }
16
+ </script>
17
+ </head>
18
+ <body class="jspec" onLoad="runSuites();">
19
+ <div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
20
+ <div id="jspec"></div>
21
+ <div id="jspec-bottom"></div>
22
+ </body>
23
+ </html>
data/spec/dom.html ADDED
@@ -0,0 +1,25 @@
1
+ <html>
2
+ <head>
3
+ <link type="text/css" rel="stylesheet" href="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.css" />
4
+ <script src="/Users/bmaddy/rails/bmaddy/jspec_runner/public/javascripts/jquery-1.4.2.min.js" type="text/javascript"></script>
5
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.js"></script>
6
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.jquery.js"></script>
7
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.timers.js"></script>
8
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.xhr.js"></script>
9
+ <script src="../lib/yourlib.js"></script>
10
+ <script src="unit/spec.helper.js"></script>
11
+ <script>
12
+ function runSuites() {
13
+ JSpec
14
+ .exec('unit/spec.js')
15
+ .run({ fixturePath: 'fixtures' })
16
+ .report()
17
+ }
18
+ </script>
19
+ </head>
20
+ <body class="jspec" onLoad="runSuites();">
21
+ <div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
22
+ <div id="jspec"></div>
23
+ <div id="jspec-bottom"></div>
24
+ </body>
25
+ </html>
@@ -0,0 +1,25 @@
1
+ <html>
2
+ <head>
3
+ <link type="text/css" rel="stylesheet" href="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.css" />
4
+ <script type="text/javascript" src="../public/javascripts/jquery-1.4.2.min.js"></script>
5
+ <script type="text/javascript" src="../public/javascripts/change_body.js"></script>
6
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.js"></script>
7
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.jquery.js"></script>
8
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.timers.js"></script>
9
+ <script src="/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.xhr.js"></script>
10
+ <script src="unit/spec.helper.js"></script>
11
+ <script>
12
+ function runSuites() {
13
+ JSpec
14
+ .exec('unit/spec.page.js')
15
+ .run({ fixturePath: 'fixtures' })
16
+ .report()
17
+ }
18
+ </script>
19
+ </head>
20
+ <body class="jspec" onLoad="runSuites();">
21
+ <div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
22
+ <div id="jspec"></div>
23
+ <div id="jspec-bottom"></div>
24
+ </body>
25
+ </html>
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <head>
3
+ <script type="text/javascript" src="javascripts/jquery-1.4.2.min.js"></script>
4
+ <script type="text/javascript" src="javascripts/change_body.js"></script>
5
+ <title>page title</title>
6
+ </head>
7
+ <body onload="change_body(document.body)">
8
+ <div><p>initial content</p></div>
9
+ </body>
10
+ </html>
data/spec/node.js ADDED
@@ -0,0 +1,10 @@
1
+
2
+ require.paths.unshift('spec', '/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib', 'lib')
3
+ require('jspec')
4
+ require('unit/spec.helper')
5
+ require('yourlib')
6
+
7
+ JSpec
8
+ .exec('spec/unit/spec.js')
9
+ .run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures', failuresOnly: true })
10
+ .report()
data/spec/rhino.js ADDED
@@ -0,0 +1,10 @@
1
+
2
+ load('/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.js')
3
+ load('/Users/bmaddy/.rvm/gems/ruby-1.8.7-p174/gems/jspec-4.3.2/lib/jspec.xhr.js')
4
+ load('lib/yourlib.js')
5
+ load('spec/unit/spec.helper.js')
6
+
7
+ JSpec
8
+ .exec('spec/unit/spec.js')
9
+ .run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures' })
10
+ .report()
data/spec/server.html ADDED
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <script src="/jspec/jspec.js"></script>
4
+ <script src="/jspec/jspec.xhr.js"></script>
5
+ <script src="/lib/yourlib.js"></script>
6
+ <script src="/spec/unit/spec.helper.js"></script>
7
+ <script>
8
+ function runSuites() {
9
+ JSpec
10
+ .exec('unit/spec.js')
11
+ .run({ reporter: JSpec.reporters.Server, verbose: true, failuresOnly: true, fixturePath: '/spec/fixtures' })
12
+ .report()
13
+ }
14
+ </script>
15
+ </head>
16
+ <body class="jspec" onLoad="runSuites();">
17
+ </body>
18
+ </html>
data/spec/server.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ get '/lib/*' do |path|
3
+ send_file File.dirname(__FILE__) + '/../lib/' + path
4
+ end
@@ -0,0 +1,12 @@
1
+ describe 'Page'
2
+
3
+ before_each
4
+ $page = $(fixture('page'))
5
+ end
6
+
7
+ describe 'before initialization'
8
+ it "this test should fail"
9
+ "one".should_equal "two"
10
+ end
11
+ end
12
+ end
File without changes
data/spec/unit/spec.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ describe 'YourLib'
3
+ describe '.someMethod()'
4
+ it 'should do something'
5
+ true.should.be true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ describe 'Page'
2
+
3
+ before_each
4
+ $page = $(fixture('page'))
5
+ end
6
+
7
+ describe 'before initialization'
8
+ it 'should have the initial content'
9
+ $page.find('p').html().should_equal "initial content"
10
+ end
11
+ end
12
+
13
+ describe 'initialize'
14
+ before_each
15
+ change_body($page)
16
+ end
17
+
18
+ describe 'after initialization'
19
+ it 'should have a title'
20
+ $page.find('p').html().should_equal "body changed by change_body.js"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ describe 'Page with XHR'
2
+
3
+ before_each
4
+ $page = $(fixture('page'))
5
+ end
6
+
7
+ describe 'before initialization'
8
+ it 'should have the initial content'
9
+ $page.find('p').html().should_equal "initial content"
10
+ end
11
+ end
12
+
13
+ describe 'initialize'
14
+ before_each
15
+ change_body_xhr($page)
16
+ end
17
+
18
+ describe 'after initialization'
19
+ it 'should have a title'
20
+ $page.find('p').html().should_equal "body changed by xhr response"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,99 @@
1
+ require "test/test_helper"
2
+
3
+ class FunctionalsControllerTest < ActionController::TestCase
4
+ test "be able to find and execute scripts in the head tag" do
5
+ get :page
6
+ assert_select js_dom, "body", :text => "body changed by change_body.js"
7
+ end
8
+
9
+ test "should have the <script> from @response.body and have the jSpec DOM formatter page" do
10
+ get :page
11
+
12
+ assert_select js_dom, "html", :count => 1
13
+ jspec :execs => ['unit/spec.page.js']
14
+
15
+ # <script> from @response.body
16
+ assert_select js_dom, "script[src$=?][type=?]", "javascripts/change_body.js", "text/javascript"
17
+ # jspec DOM formatter stuff
18
+ assert_select js_dom, "script[src$=?]", "jspec.js"
19
+ assert_select js_dom, "script[src$=?]", "jspec.xhr.js"
20
+ assert_select js_dom, "script[src$=?]", "spec/unit/spec.jspec_runner.helper.js"
21
+ assert_match Regexp.new(Regexp.escape(".exec('unit/spec.page.js')")), js_dom.to_s
22
+ assert_select js_dom, "body.jspec"
23
+ assert_select js_dom, "div#jspec-top" do
24
+ assert_select "#jspec-title em", :text => /\d/
25
+ end
26
+ assert_select js_dom, "div#jspec"
27
+ assert_select js_dom, "div#jspec-bottom"
28
+ end
29
+
30
+ test "a failing spec should fail" do
31
+ get :page
32
+
33
+ result = jspec(:execs => ['unit/spec.failure.js'])
34
+ expected = <<-TEXT
35
+
36
+ Page before initialization
37
+ \e[31mFailed\e[0m: this test should fail, expected "one" to be "two"
38
+ expect("one").should(equal, "two");
39
+
40
+ JSpec: \e[32m0 passes\e[0m, \e[31m1 failures\e[0m
41
+ TEXT
42
+ assert_equal false, result[:passed]
43
+ assert_equal expected, result[:output]
44
+ end
45
+
46
+ test "a failing assert_jspec should fail" do
47
+ get :page
48
+ assert_raises Test::Unit::AssertionFailedError do
49
+ assert_jspec :execs => ['unit/spec.failure.js']
50
+ end
51
+ end
52
+
53
+ test "a passing spec" do
54
+ get :page
55
+ assert_jspec :execs => ['unit/spec.page.js']
56
+ end
57
+
58
+ test "text with xhr" do
59
+ get :page
60
+ assert_jspec :execs => ['unit/spec.page_xhr.js']
61
+ end
62
+
63
+ # test "should give a message if the route doesn't exist" do
64
+ # # TODO: If the route doesn't exist we should at least get something output
65
+ # # (preferably an error, but holygrail doesn't do that yet either)
66
+ # assert_raises ActionController::RoutingError do
67
+ # assert_jspec :execs => ['unit/spec.xhr_route_error.js']
68
+ # end
69
+ # end
70
+
71
+ test "multiple passing specs" do
72
+ get :page
73
+ assert_jspec :execs => ['unit/spec.page.js', 'unit/spec.page_xhr.js']
74
+ end
75
+
76
+ test "first spec failing" do
77
+ get :page
78
+ assert_raises Test::Unit::AssertionFailedError do
79
+ assert_jspec :execs => ['unit/spec.failure.js', 'unit/spec.page_xhr.js']
80
+ end
81
+ end
82
+
83
+ test "second spec failing" do
84
+ get :page
85
+ assert_raises Test::Unit::AssertionFailedError do
86
+ assert_jspec :execs => ['unit/spec.page.js', 'unit/spec.failure.js']
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ # this method is only here until my patch to add it to holygrail is accepted
93
+ # TODO: consider not requiring holygrail
94
+ def js_dom
95
+ # force holygrail to set @__page
96
+ js('true') unless @__page
97
+ HTML::Document.new(@__page.to_html, false, true).root
98
+ end
99
+ end
@@ -0,0 +1,99 @@
1
+ require "test/test_helper"
2
+
3
+ class IntegrationTest < ActionController::IntegrationTest
4
+ test "be able to find and execute scripts in the head tag" do
5
+ get "page"
6
+ assert_select js_dom, "body", :text => "body changed by change_body.js"
7
+ end
8
+
9
+ test "should have the <script> from @response.body and have the jSpec DOM formatter page" do
10
+ get "page"
11
+
12
+ assert_select js_dom, "html", :count => 1
13
+ jspec :execs => ['unit/spec.page.js']
14
+
15
+ # <script> from @response.body
16
+ assert_select js_dom, "script[src$=?][type=?]", "javascripts/change_body.js", "text/javascript"
17
+ # jspec DOM formatter stuff
18
+ assert_select js_dom, "script[src$=?]", "jspec.js"
19
+ assert_select js_dom, "script[src$=?]", "jspec.xhr.js"
20
+ assert_select js_dom, "script[src$=?]", "spec/unit/spec.jspec_runner.helper.js"
21
+ assert_match Regexp.new(Regexp.escape(".exec('unit/spec.page.js')")), js_dom.to_s
22
+ assert_select js_dom, "body.jspec"
23
+ assert_select js_dom, "div#jspec-top" do
24
+ assert_select "#jspec-title em", :text => /\d/
25
+ end
26
+ assert_select js_dom, "div#jspec"
27
+ assert_select js_dom, "div#jspec-bottom"
28
+ end
29
+
30
+ test "a failing spec should fail" do
31
+ get "page"
32
+
33
+ result = jspec(:execs => ['unit/spec.failure.js'])
34
+ expected = <<-TEXT
35
+
36
+ Page before initialization
37
+ \e[31mFailed\e[0m: this test should fail, expected "one" to be "two"
38
+ expect("one").should(equal, "two");
39
+
40
+ JSpec: \e[32m0 passes\e[0m, \e[31m1 failures\e[0m
41
+ TEXT
42
+ assert_equal false, result[:passed]
43
+ assert_equal expected, result[:output]
44
+ end
45
+
46
+ test "a failing assert_jspec should fail" do
47
+ get "page"
48
+ assert_raises Test::Unit::AssertionFailedError do
49
+ assert_jspec :execs => ['unit/spec.failure.js']
50
+ end
51
+ end
52
+
53
+ test "a passing spec" do
54
+ get "page"
55
+ assert_jspec :execs => ['unit/spec.page.js']
56
+ end
57
+
58
+ test "text with xhr" do
59
+ get "page"
60
+ assert_jspec :execs => ['unit/spec.page_xhr.js']
61
+ end
62
+
63
+ # test "should give a message if the route doesn't exist" do
64
+ # # TODO: If the route doesn't exist we should at least get something output
65
+ # # (preferably an error, but holygrail doesn't do that yet either)
66
+ # assert_raises ActionController::RoutingError do
67
+ # assert_jspec :execs => ['unit/spec.xhr_route_error.js']
68
+ # end
69
+ # end
70
+
71
+ test "multiple passing specs" do
72
+ get "page"
73
+ assert_jspec :execs => ['unit/spec.page.js', 'unit/spec.page_xhr.js']
74
+ end
75
+
76
+ test "first spec failing" do
77
+ get "page"
78
+ assert_raises Test::Unit::AssertionFailedError do
79
+ assert_jspec :execs => ['unit/spec.failure.js', 'unit/spec.page_xhr.js']
80
+ end
81
+ end
82
+
83
+ test "second spec failing" do
84
+ get "page"
85
+ assert_raises Test::Unit::AssertionFailedError do
86
+ assert_jspec :execs => ['unit/spec.page.js', 'unit/spec.failure.js']
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ # this method is only here until my patch to add it to holygrail is accepted
93
+ # TODO: consider not requiring holygrail
94
+ def js_dom
95
+ # force holygrail to set @__page
96
+ js('true') unless @__page
97
+ HTML::Document.new(@__page.to_html, false, true).root
98
+ end
99
+ end