js_spec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
2
+
3
+ module JsSpec
4
+ describe File do
5
+ attr_reader :file
6
+
7
+ before do
8
+ @file = JsSpec::File.new(absolute_path, relative_path)
9
+ end
10
+
11
+ def absolute_path
12
+ "#{spec_root_path}/failing_spec.js"
13
+ end
14
+
15
+ def relative_path
16
+ "/specs/failing_spec.js"
17
+ end
18
+
19
+ describe "#absolute_path" do
20
+ it "returns the absolute path passed into the initializer" do
21
+ file.absolute_path.should == absolute_path
22
+ end
23
+ end
24
+
25
+ describe "#relative_path" do
26
+ it "returns the relative path passed into the initializer" do
27
+ file.relative_path.should == relative_path
28
+ end
29
+ end
30
+
31
+ describe "#get" do
32
+ attr_reader :response
33
+ before do
34
+ @response = Rack::Response.new
35
+ mock.proxy(Server).response.returns(@response)
36
+ end
37
+
38
+ it "returns the contents of the file" do
39
+ file.get.should == ::File.read(absolute_path)
40
+ end
41
+
42
+ describe "when File has an extension" do
43
+ describe '.js' do
44
+ it "sets Content-Type to text/javascript" do
45
+ file.get
46
+ response.content_type.should == "text/javascript"
47
+ end
48
+ end
49
+
50
+ describe '.css' do
51
+ it "sets Content-Type to text/css" do
52
+ file.get
53
+ response.content_type.should == "text/css"
54
+ end
55
+
56
+ def absolute_path
57
+ "#{core_path}/JSSpec.css"
58
+ end
59
+
60
+ def relative_path
61
+ "/core/JSSpec.css"
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "==" do
68
+ it "returns true when passed a file with the same absolute and relative paths" do
69
+ file.should == JsSpec::File.new(absolute_path, relative_path)
70
+ end
71
+
72
+ it "returns false when passed a file with a different absolute or relative path" do
73
+ file.should_not == JsSpec::File.new(absolute_path, "bogus")
74
+ file.should_not == JsSpec::File.new("bogus", relative_path)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,156 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
2
+
3
+ module JsSpec
4
+ describe Server do
5
+ describe "HTTP GET" do
6
+ specify "'/specs' returns an HTML test runner including all specs files" do
7
+ result = get("/specs").body
8
+ result.should include('<script type="text/javascript" src="/specs/failing_spec.js"></script>')
9
+ result.should include('<script type="text/javascript" src="/specs/foo/failing_spec.js"></script>')
10
+ result.should include('<script type="text/javascript" src="/specs/foo/passing_spec.js"></script>')
11
+ end
12
+
13
+ specify "'/specs/failing_spec', returns an HTML test runner including it" do
14
+ result = get("/specs/failing_spec").body
15
+ result.should include('<script type="text/javascript" src="/specs/failing_spec.js"></script>')
16
+ end
17
+
18
+ specify "'/specs/foo', returns an HTML test runner including all specs below foo" do
19
+ result = get("/specs/foo").body
20
+ result.should include('<script type="text/javascript" src="/specs/foo/failing_spec.js"></script>')
21
+ result.should include('<script type="text/javascript" src="/specs/foo/passing_spec.js"></script>')
22
+ end
23
+
24
+ specify "'/specs/nonexistent', raises an error" do
25
+ lambda { get("/specs/nonexistent") }.should raise_error
26
+ end
27
+
28
+ specify "'/core/JSSpec.js', returns the contents of the file" do
29
+ result = get("/core/JSSpec.js").body
30
+ result.should == ::File.read("#{Server.core_path}/JSSpec.js")
31
+ end
32
+ end
33
+
34
+ describe ".run" do
35
+ attr_reader :server_instance
36
+ before do
37
+ @server_instance = Server.instance
38
+ Server.instance = nil
39
+ end
40
+
41
+ it "instantiates an instance of Server and starts a Rack Mongrel handler" do
42
+ host = Server::DEFAULT_HOST
43
+ port = Server::DEFAULT_PORT
44
+
45
+ mock.proxy(Server).new(spec_root_path, implementation_root_path, host, port) do
46
+ server_instance
47
+ end
48
+ mock(Rack::Handler::Mongrel).run(server_instance, {:Host => host, :Port => port})
49
+
50
+ Server.run(spec_root_path, implementation_root_path)
51
+ end
52
+
53
+ it "when passed a custom host and port, sets the host and port to the passed in value" do
54
+ host = 'foobar.com'
55
+ port = 80
56
+
57
+ mock.proxy(Server).new(spec_root_path, implementation_root_path, host, port) do
58
+ server_instance
59
+ end
60
+ mock(Rack::Handler::Mongrel).run(server_instance, {:Host => host, :Port => port})
61
+
62
+ Server.run(spec_root_path, implementation_root_path, {:Host => host, :Port => port})
63
+ end
64
+ end
65
+
66
+ describe ".spec_root" do
67
+ it "returns the Dir " do
68
+ Server.spec_root_path.should == ::File.expand_path(spec_root_path)
69
+ end
70
+ end
71
+
72
+ describe ".spec_root_path" do
73
+ it "returns the absolute path of the specs root directory" do
74
+ Server.spec_root_path.should == ::File.expand_path(spec_root_path)
75
+ end
76
+ end
77
+
78
+ describe ".core_path" do
79
+ it "returns the expanded path to the JsSpec core directory" do
80
+ dir = ::File.dirname(__FILE__)
81
+ Server.core_path.should == ::File.expand_path("#{dir}/../../core")
82
+ end
83
+ end
84
+
85
+ describe ".implementation_root_path" do
86
+ it "returns the expanded path to the JsSpec implementations directory" do
87
+ dir = ::File.dirname(__FILE__)
88
+ Server.implementation_root_path.should == ::File.expand_path(implementation_root_path)
89
+ end
90
+ end
91
+
92
+ describe ".request" do
93
+ it "returns request in progress for the thread" do
94
+ the_request = nil
95
+ stub.instance_of(WebRoot).locate('somedir') do
96
+ the_request = JsSpec::Server.request
97
+ Thread.current[:request].should == the_request
98
+ thread2 = Thread.new do
99
+ Thread.current[:request].should be_nil
100
+ end
101
+ thread2.join
102
+
103
+ mock_resource = Object.new
104
+ stub(mock_resource).get.returns("")
105
+ mock_resource
106
+ end
107
+
108
+ get('/somedir')
109
+
110
+ the_request.path_info.should == '/somedir'
111
+ end
112
+
113
+ it "resets to nil when the request is finished" do
114
+ get('/core')
115
+
116
+ JsSpec::Server.request.should be_nil
117
+ end
118
+ end
119
+
120
+ describe ".response" do
121
+ it "returns response in progress" do
122
+ the_response = nil
123
+ stub.instance_of(WebRoot).locate('somedir') do
124
+ the_response = JsSpec::Server.response
125
+ Thread.current[:response].should == the_response
126
+ thread2 = Thread.new do
127
+ Thread.current[:response].should be_nil
128
+ end
129
+ thread2.join
130
+
131
+ mock_resource = Object.new
132
+ stub(mock_resource).get {"The text"}
133
+ mock_resource
134
+ end
135
+
136
+ get('/somedir')
137
+
138
+ the_response.body.should == 'The text'
139
+ end
140
+
141
+ it "resets to nil when the response is finished" do
142
+ get('/core')
143
+
144
+ JsSpec::Server.response.should be_nil
145
+ end
146
+ end
147
+
148
+ describe "#initialize" do
149
+ it "expands relative paths for #spec_root_path and #implementation_root_path" do
150
+ server = Server.new("foo", "bar")
151
+ server.spec_root_path.should == ::File.expand_path("foo")
152
+ server.implementation_root_path.should == ::File.expand_path("bar")
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
2
+
3
+ module JsSpec
4
+ describe SpecDirRunner do
5
+ attr_reader :dir, :runner
6
+
7
+ before do
8
+ @dir = Dir.new(spec_root_path, '/specs')
9
+ @runner = SpecDirRunner.new(dir)
10
+ end
11
+
12
+ describe "#spec_files" do
13
+ it "returns a File for each *_spec.js file in the directory" do
14
+ spec_files = runner.spec_files
15
+
16
+ spec_files.should contain_spec_file_with_correct_paths("/failing_spec.js")
17
+ spec_files.should contain_spec_file_with_correct_paths("/foo/failing_spec.js")
18
+ spec_files.should contain_spec_file_with_correct_paths("/foo/passing_spec.js")
19
+ end
20
+ end
21
+
22
+ describe "#get" do
23
+ attr_reader :html, :doc
24
+ before do
25
+ @html = runner.get()
26
+ @doc = Hpricot(html)
27
+ end
28
+
29
+ it "returns script tags for each test javascript file" do
30
+ doc.at("script[@src='/specs/failing_spec.js']").should exist
31
+ end
32
+
33
+ it "returns the js specs template" do
34
+ doc.at("link[@href='/core/JSSpec.css']").should exist
35
+ doc.at("script[@src='/core/JSSpec.js']").should exist
36
+ doc.at("script[@src='/core/JSSpecExtensions.js']").should exist
37
+ doc.at("body").inner_html.should be_empty
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
2
+
3
+ module JsSpec
4
+ describe SpecFileRunner, "#spec_files" do
5
+ attr_reader :absolute_path, :relative_path, :file, :runner
6
+
7
+ before do
8
+ @absolute_path = "#{spec_root_path}/failing_spec.js"
9
+ @relative_path = "/specs/failing_spec.js"
10
+ @file = File.new(absolute_path, relative_path)
11
+ @runner = SpecFileRunner.new(file)
12
+ end
13
+
14
+ it "returns the single File to run in an Array" do
15
+ runner.spec_files.should == [file]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
2
+
3
+ module JsSpec
4
+ describe SuiteResult do
5
+ attr_reader :result
6
+ before do
7
+ @result = SuiteResult.new
8
+ end
9
+
10
+ describe "#post" do
11
+ attr_reader :stdout
12
+ before do
13
+ @stdout = StringIO.new
14
+ SuiteResult.const_set(:STDOUT, stdout)
15
+ end
16
+ after do
17
+ SuiteResult.__send__(:remove_const, :STDOUT)
18
+ end
19
+
20
+ it "writes the body of the request to stdout" do
21
+ body = "The text in the POST body"
22
+ request = Rack::Request.new({'rack.input' => StringIO.new("text=#{body}")})
23
+ request.body.string.should == "text=#{body}"
24
+ stub.proxy(Server).request {request}
25
+
26
+ result.post
27
+ stdout.string.should == "#{body}\n"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,84 @@
1
+ require "rubygems"
2
+ dir = File.dirname(__FILE__)
3
+ $LOAD_PATH.unshift "#{dir}/../../../plugins/rspec/lib"
4
+ require "spec"
5
+
6
+ $LOAD_PATH.unshift "#{dir}/../../lib"
7
+ require "js_spec"
8
+ require "hpricot"
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
13
+
14
+ module Spec
15
+ module Matchers
16
+ class Exist
17
+ def matches?(actual)
18
+ @actual = actual
19
+ !@actual.nil?
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module Spec::Example::ExampleMethods
26
+ attr_reader :spec_root_path, :implementation_root_path, :server
27
+ before(:all) do
28
+ dir = File.dirname(__FILE__)
29
+ @spec_root_path = ::File.expand_path("#{dir}/../example_specs")
30
+ @implementation_root_path = ::File.expand_path("#{dir}/../example_implementation")
31
+ end
32
+
33
+ before(:each) do
34
+ JsSpec::Server.instance = JsSpec::Server.new(spec_root_path, implementation_root_path)
35
+ @server = JsSpec::Server.instance
36
+ end
37
+
38
+ def get(url, params={})
39
+ request(:get, url, params)
40
+ end
41
+
42
+ def post(url, params={})
43
+ request(:post, url, params)
44
+ end
45
+
46
+ def put(url, params={})
47
+ request(:put, url, params)
48
+ end
49
+
50
+ def delete(url, params={})
51
+ request(:delete, url, params)
52
+ end
53
+
54
+ def request(method, url, params={})
55
+ @request = Rack::MockRequest.new(server)
56
+ @request.__send__(method, url, params)
57
+ end
58
+
59
+ def core_path
60
+ JsSpec::Server.core_path
61
+ end
62
+
63
+ def spec_file(relative_path)
64
+ absolute_path = File.expand_path(spec_root_path + relative_path)
65
+ JsSpec::File.new(absolute_path, "/specs#{relative_path}")
66
+ end
67
+
68
+ def spec_dir(relative_path="")
69
+ absolute_path = File.expand_path(spec_root_path + relative_path)
70
+ JsSpec::Dir.new(absolute_path, "/specs#{relative_path}")
71
+ end
72
+
73
+ def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
74
+ expected_absolute_path = spec_root_path + path_relative_to_spec_root
75
+ expected_relative_path = "/specs" + path_relative_to_spec_root
76
+
77
+ ::Spec::Matchers::SimpleMatcher.new(expected_relative_path) do |globbed_files|
78
+ file = globbed_files.find do |file|
79
+ file.absolute_path == expected_absolute_path
80
+ end
81
+ file && file.relative_path == expected_relative_path
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
2
+
3
+ module JsSpec
4
+ describe WebRoot do
5
+ attr_reader :root_dir
6
+ before(:each) do
7
+ @root_dir = WebRoot.new
8
+ end
9
+
10
+ describe "#locate" do
11
+ it "when passed 'specs', returns a SpecDirRunner representing the specs" do
12
+ runner = root_dir.locate('specs')
13
+ runner.should == spec_dir
14
+ end
15
+
16
+ it "when passed 'core', returns a Dir representing the JsSpec core directory" do
17
+ runner = root_dir.locate('core')
18
+ runner.should == JsSpec::Dir.new(JsSpec::Server.core_path, '/core')
19
+ end
20
+
21
+ it "when passed 'implementations', returns a Dir representing the javascript implementations directory" do
22
+ runner = root_dir.locate('implementations')
23
+ runner.should == JsSpec::Dir.new(JsSpec::Server.implementation_root_path, '/implementations')
24
+ end
25
+
26
+ it "when passed 'results', returns a SuiteResult" do
27
+ runner = root_dir.locate('results')
28
+ runner.should be_instance_of(JsSpec::SuiteResult)
29
+ end
30
+
31
+ it "when not passed 'core' or 'specs', raises an error" do
32
+ lambda do
33
+ root_dir.locate('invalid')
34
+ end.should raise_error
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,10 @@
1
+ class JsSpecUnitSuite
2
+ def run
3
+ dir = File.dirname(__FILE__)
4
+ Dir["#{dir}/unit/**/*_spec.rb"].each do |file|
5
+ require file
6
+ end
7
+ end
8
+ end
9
+
10
+ JsSpecUnitSuite.new.run
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: js_spec
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-12-18 00:00:00 -08:00
8
+ summary: JsSpec is a server for the JSSpec javascript framework.
9
+ require_paths:
10
+ - lib
11
+ email: brian@pivotallabs.com
12
+ homepage: http://pivotallabs.com
13
+ rubyforge_project: pivotalrb
14
+ description: JsSpec is a server for the JSSpec javascript framework.
15
+ autorequire: js_spec
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Brian Takita & Nathan Sobo
31
+ files:
32
+ - Rakefile
33
+ - CHANGES
34
+ - README
35
+ - lib/js_spec/spec_file_runner.rb
36
+ - lib/js_spec/spec_runner.rb
37
+ - lib/js_spec/dir.rb
38
+ - lib/js_spec/spec_dir_runner.rb
39
+ - lib/js_spec/web_root.rb
40
+ - lib/js_spec/suite_result.rb
41
+ - lib/js_spec/file.rb
42
+ - lib/js_spec/server.rb
43
+ - lib/js_spec.rb
44
+ - core/JSSpec.js
45
+ - core/diff_match_patch.js
46
+ - core/JSSpecExtensions.js
47
+ - core/exp
48
+ - core/JSSpec.css
49
+ - core/demo.html
50
+ - core/COPYING
51
+ - bin/js_spec_server
52
+ - spec/spec_suite.rb
53
+ - spec/unit_spec_suite.rb
54
+ - spec/functional/server_spec.rb
55
+ - spec/functional/functional_spec_helper.rb
56
+ - spec/functional_spec_suite.rb
57
+ - spec/unit/spec_file_runner_spec.rb
58
+ - spec/unit/file_spec.rb
59
+ - spec/unit/spec_dir_runner_spec.rb
60
+ - spec/unit/server_spec.rb
61
+ - spec/unit/dir_spec.rb
62
+ - spec/unit/web_root_spec.rb
63
+ - spec/unit/suite_result_spec.rb
64
+ - spec/unit/unit_spec_helper.rb
65
+ test_files: []
66
+
67
+ rdoc_options:
68
+ - --main
69
+ - README
70
+ - --inline-source
71
+ - --line-numbers
72
+ extra_rdoc_files:
73
+ - README
74
+ - CHANGES
75
+ executables:
76
+ - js_spec_server
77
+ extensions: []
78
+
79
+ requirements: []
80
+
81
+ dependencies: []
82
+