js_spec 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGES +12 -0
  2. data/README +2 -1
  3. data/Rakefile +2 -3
  4. data/core/JSSpecExtensions.js +18 -16
  5. data/lib/js_spec/resources/{spec_runner.rb → spec.rb} +4 -8
  6. data/lib/js_spec/resources.rb +1 -10
  7. data/lib/js_spec.rb +19 -20
  8. data/spec/integration/integration_spec.rb +14 -3
  9. data/spec/integration/integration_spec_helper.rb +1 -2
  10. data/spec/unit/js_test_core/resources/spec_dir_spec.rb +35 -0
  11. data/spec/unit/js_test_core/resources/spec_file_spec.rb +33 -0
  12. data/spec/unit/unit_spec_helper.rb +9 -9
  13. metadata +7 -46
  14. data/core/jquery.js +0 -2992
  15. data/lib/js_spec/client.rb +0 -50
  16. data/lib/js_spec/guid.rb +0 -153
  17. data/lib/js_spec/rack/commonlogger.rb +0 -5
  18. data/lib/js_spec/rack.rb +0 -2
  19. data/lib/js_spec/rails_server.rb +0 -22
  20. data/lib/js_spec/resources/dir.rb +0 -60
  21. data/lib/js_spec/resources/file.rb +0 -32
  22. data/lib/js_spec/resources/runners/firefox_runner.rb +0 -71
  23. data/lib/js_spec/resources/runners.rb +0 -15
  24. data/lib/js_spec/resources/spec_dir_runner.rb +0 -15
  25. data/lib/js_spec/resources/spec_file_runner.rb +0 -15
  26. data/lib/js_spec/resources/suite.rb +0 -24
  27. data/lib/js_spec/resources/suite_finish.rb +0 -20
  28. data/lib/js_spec/resources/web_root.rb +0 -34
  29. data/lib/js_spec/server.rb +0 -98
  30. data/lib/js_spec/thin/backends/js_spec_server.rb +0 -9
  31. data/lib/js_spec/thin/js_spec_connection.rb +0 -42
  32. data/lib/js_spec/thin.rb +0 -3
  33. data/spec/unit/js_spec/client_spec.rb +0 -137
  34. data/spec/unit/js_spec/rails_server_spec.rb +0 -45
  35. data/spec/unit/js_spec/resources/dir_spec.rb +0 -84
  36. data/spec/unit/js_spec/resources/file_spec.rb +0 -87
  37. data/spec/unit/js_spec/resources/runner_spec.rb +0 -24
  38. data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +0 -152
  39. data/spec/unit/js_spec/resources/spec_dir_runner_spec.rb +0 -48
  40. data/spec/unit/js_spec/resources/spec_file_runner_spec.rb +0 -20
  41. data/spec/unit/js_spec/resources/suite_finish_spec.rb +0 -42
  42. data/spec/unit/js_spec/resources/suite_spec.rb +0 -44
  43. data/spec/unit/js_spec/resources/web_root_spec.rb +0 -55
  44. data/spec/unit/js_spec/server_spec.rb +0 -154
  45. data/spec/unit/thin/js_spec_connection_spec.rb +0 -64
@@ -1,55 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
-
3
- module JsSpec
4
- module Resources
5
- describe WebRoot do
6
- attr_reader :web_root
7
- before(:each) do
8
- @web_root = WebRoot.new(public_path)
9
- end
10
-
11
- describe "#locate" do
12
- it "when passed 'specs', returns a SpecDirRunner representing the specs" do
13
- runner = web_root.locate('specs')
14
- runner.should == spec_dir
15
- end
16
-
17
- it "when passed 'core', returns a Dir representing the JsSpec core directory" do
18
- runner = web_root.locate('core')
19
- runner.should == Resources::Dir.new(JsSpec::Server.core_path, '/core')
20
- end
21
-
22
- it "when passed 'implementations', returns a Dir representing the javascript implementations directory" do
23
- runner = web_root.locate('implementations')
24
- runner.should == Resources::Dir.new(JsSpec::Server.implementation_root_path, '/implementations')
25
- end
26
-
27
- it "when passed 'results', returns a Suite" do
28
- runner = web_root.locate('suites')
29
- runner.should == Resources::Suite
30
- end
31
-
32
- it "when passed 'runners', returns a Runner" do
33
- runner = web_root.locate('runners')
34
- runner.should be_instance_of(Resources::Runners)
35
- end
36
-
37
- it "when passed a directory that is in the public_path, returns a Dir representing that directory" do
38
- runner = web_root.locate('stylesheets')
39
- runner.should == Resources::Dir.new("#{JsSpec::Server.public_path}/stylesheets", '/stylesheets')
40
- end
41
-
42
- it "when passed a file that is in the public_path, returns a File representing that file" do
43
- runner = web_root.locate('robots.txt')
44
- runner.should == Resources::File.new("#{JsSpec::Server.public_path}/robots.txt", '/robots.txt')
45
- end
46
-
47
- it "when not passed 'core' or 'specs', raises an error" do
48
- lambda do
49
- web_root.locate('invalid')
50
- end.should raise_error
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,154 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
-
3
- module JsSpec
4
- describe Server do
5
- attr_reader :result
6
-
7
- before do
8
- @result = ""
9
- stub(EventMachine).send_data do |signature, data, data_length|
10
- @result << data
11
- end
12
- stub(EventMachine).close_connection
13
- end
14
-
15
- describe "HTTP GET" do
16
- specify "'/specs' returns an HTML test runner including all specs files" do
17
- result = get("/specs").body
18
- result.should include('<script type="text/javascript" src="/specs/failing_spec.js"></script>')
19
- result.should include('<script type="text/javascript" src="/specs/foo/failing_spec.js"></script>')
20
- result.should include('<script type="text/javascript" src="/specs/foo/passing_spec.js"></script>')
21
- end
22
-
23
- specify "'/specs/failing_spec', returns an HTML test runner including it" do
24
- result = get("/specs/failing_spec").body
25
- result.should include('<script type="text/javascript" src="/specs/failing_spec.js"></script>')
26
- end
27
-
28
- specify "'/specs/foo', returns an HTML test runner including all specs below foo" do
29
- result = get("/specs/foo").body
30
- result.should include('<script type="text/javascript" src="/specs/foo/failing_spec.js"></script>')
31
- result.should include('<script type="text/javascript" src="/specs/foo/passing_spec.js"></script>')
32
- end
33
-
34
- specify "'/specs/nonexistent', raises an error" do
35
- lambda { get("/specs/nonexistent") }.should raise_error
36
- end
37
-
38
- specify "'/core/JSSpec.js', returns the contents of the file" do
39
- response = get("/core/JSSpec.js")
40
- response.body.should == ::File.read("#{Server.core_path}/JSSpec.js")
41
- end
42
-
43
- specify "'/stylesheets/example.css', returns the contents of the file" do
44
- response = get("/stylesheets/example.css")
45
- response.body.should == ::File.read("#{Server.public_path}/stylesheets/example.css")
46
- end
47
-
48
- specify "'/invalid/path', shows the full invalid path in the error message" do
49
- lambda do
50
- get("/invalid/path")
51
- end.should raise_error(Exception, Regexp.new("/invalid/path"))
52
- end
53
- end
54
-
55
- describe ".run" do
56
- attr_reader :server_instance
57
- before do
58
- @server_instance = Server.instance
59
- Server.instance = nil
60
- end
61
-
62
- it "instantiates an instance of Server and starts a Rack Thin handler" do
63
- host = DEFAULT_HOST
64
- port = DEFAULT_PORT
65
-
66
- mock(EventMachine).run.yields
67
- mock(EventMachine).start_server(host, port, ::Thin::JsSpecConnection)
68
-
69
- Server.run(spec_root_path, implementation_root_path, public_path)
70
- end
71
-
72
- it "when passed a custom host and port, sets the host and port to the passed in value" do
73
- host = 'foobar.com'
74
- port = 80
75
-
76
- mock(EventMachine).run.yields
77
- mock(EventMachine).start_server(host, port, ::Thin::JsSpecConnection)
78
-
79
- Server.run(spec_root_path, implementation_root_path, public_path, {:Host => host, :Port => port})
80
- end
81
- end
82
-
83
- describe ".spec_root" do
84
- it "returns the Dir " do
85
- Server.spec_root_path.should == spec_root_path
86
- end
87
- end
88
-
89
- describe ".spec_root_path" do
90
- it "returns the absolute path of the specs root directory" do
91
- Server.spec_root_path.should == spec_root_path
92
- end
93
- end
94
-
95
- describe ".public_path" do
96
- it "returns the expanded path of the public path" do
97
- Server.public_path.should == public_path
98
- end
99
- end
100
-
101
- describe ".core_path" do
102
- it "returns the expanded path to the JsSpec core directory" do
103
- dir = ::File.dirname(__FILE__)
104
- Server.core_path.should == ::File.expand_path("#{dir}/../../../core")
105
- end
106
- end
107
-
108
- describe ".implementation_root_path" do
109
- it "returns the expanded path to the JsSpec implementations directory" do
110
- dir = ::File.dirname(__FILE__)
111
- Server.implementation_root_path.should == implementation_root_path
112
- end
113
- end
114
-
115
- describe "#call" do
116
- describe "when there is an error" do
117
- attr_reader :top_line_of_backtrace
118
- before do
119
- @top_line_of_backtrace = __LINE__ + 2
120
- stub.instance_of(Resources::WebRoot).locate('somedir') do
121
- raise "Foobar"
122
- end
123
- end
124
-
125
- it "shows the full request path in the error message" do
126
- lambda do
127
- get('/somedir')
128
- end.should raise_error(Exception, Regexp.new("/somedir"))
129
- end
130
-
131
- it "uses the backtrace from where the original error was raised" do
132
- no_error = true
133
- begin
134
- get('/somedir')
135
- rescue Exception => e
136
- no_error = false
137
- top_of_backtrace = e.backtrace.first.split(":")
138
- backtrace_file = ::File.expand_path(top_of_backtrace[0])
139
- backtrace_line = Integer(top_of_backtrace[1])
140
- backtrace_file.should == __FILE__
141
- backtrace_line.should == top_line_of_backtrace
142
- end
143
- raise "There should have been an error" if no_error
144
- end
145
- end
146
- end
147
-
148
- describe "#root_url" do
149
- it "returns the url of the site's root" do
150
- server.root_url.should == "http://#{server.host}:#{server.port}"
151
- end
152
- end
153
- end
154
- end
@@ -1,64 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
-
3
- module Thin
4
- describe JsSpecConnection do
5
- describe "#process" do
6
- attr_reader :connection, :result
7
- before do
8
- @connection = JsSpecConnection.new('signature')
9
- stub(connection).socket_address {'0.0.0.0'}
10
-
11
- @result = ""
12
- stub(EventMachine).send_data do |signature, data, data_length|
13
- result << data
14
- end
15
- end
16
-
17
- describe "and the call is successful" do
18
- describe "and the body is not empty" do
19
- attr_reader :somedir_resource
20
- before do
21
- mock(app = Object.new).call(is_a(Hash)) do
22
- [200, {}, 'The Body']
23
- end
24
- connection.app = app
25
- end
26
-
27
- it "sends the response to the socket and closes the connection" do
28
- mock(connection).close_connection_after_writing
29
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
30
- result.should include("The Body")
31
- end
32
- end
33
-
34
- describe "and the body is empty" do
35
- attr_reader :somedir_resource
36
- before do
37
- mock(app = Object.new).call(is_a(Hash)) do
38
- [200, {}, []]
39
- end
40
- connection.app = app
41
- end
42
-
43
- it "keeps the connection open" do
44
- dont_allow(connection).close_connection_after_writing
45
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
46
- end
47
- end
48
- end
49
-
50
- describe "and the call raises an error" do
51
- it "logs the error and closes the connection" do
52
- mock(app = Object.new).call(is_a(Hash)) do
53
- raise "An Error"
54
- end
55
- connection.app = app
56
- mock(connection).log(anything).at_least(1)
57
- mock(connection).close_connection
58
-
59
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
60
- end
61
- end
62
- end
63
- end
64
- end