spassky 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
-
3
2
  require 'capybara'
4
3
  require 'capybara/dsl'
5
4
  require 'rack/test'
@@ -14,6 +13,7 @@ module Spassky::Server
14
13
 
15
14
  before do
16
15
  RandomStringGenerator.stub!(:random_string).and_return("random-string")
16
+ header "User-Agent", "some user agent"
17
17
  end
18
18
 
19
19
  def app
@@ -33,11 +33,24 @@ module Spassky::Server
33
33
  end
34
34
  end
35
35
 
36
+ describe "GET /devices/list" do
37
+ it "returns a list of devices" do
38
+ devices = ["iphone", "nokia"]
39
+ device_list.should_receive(:recently_connected_devices).and_return(devices)
40
+ get "/devices/list"
41
+ last_response.body.should == devices.to_json
42
+ end
43
+ end
44
+
36
45
  describe "GET /device/idle/123" do
46
+ before do
47
+ @device_database = mock :device_database
48
+ SingletonDeviceDatabase.stub!(:instance).and_return(@device_database)
49
+ @device_database.stub!(:device_identifier).and_return("anything")
50
+ end
37
51
 
38
- it "tells the device list that the device connected" do
39
- device_list.should_receive(:update_last_connected).with("some user agent")
40
- header "User-Agent", "some user agent"
52
+ it "tells the device list that the device connected using the device identifier" do
53
+ device_list.should_receive(:update_last_connected).with("anything")
41
54
  get "/device/idle/123"
42
55
  end
43
56
 
@@ -56,8 +69,7 @@ module Spassky::Server
56
69
  test = mock(:test, :contents => "test contents")
57
70
  test.stub!(:id).and_return("the-test-id")
58
71
  test.stub!(:name).and_return("the-test-name")
59
- TestRun.stub!(:find_next_to_run_for_user_agent).with("some user agent").and_return(test)
60
- header "User-Agent", "some user agent"
72
+ TestRun.stub!(:find_next_to_run_for_user_agent).with("anything").and_return(test)
61
73
  get '/device/idle/123'
62
74
  last_response.should be_redirect
63
75
  last_response.location.should == 'http://example.org/test_runs/the-test-id/run/a-random-string/the-test-name'
@@ -69,8 +81,7 @@ module Spassky::Server
69
81
  it "saves the test result" do
70
82
  test = mock(:test)
71
83
  TestRun.stub!(:find).with('123').and_return(test)
72
- header "User-Agent", "the user agent"
73
- test.should_receive(:save_results_for_user_agent).with(:user_agent => "the user agent", :status => "pass")
84
+ test.should_receive(:save_results_for_user_agent).with(:user_agent => "some user agent", :status => "pass")
74
85
  get "/test_runs/123/run/random/assert?status=pass"
75
86
  end
76
87
  end
@@ -88,7 +99,6 @@ module Spassky::Server
88
99
  it "returns the specified file" do
89
100
  test = mock(:test, :name => "fake_test.html.file", :contents => @test_contents)
90
101
  TestRun.stub!(:find).with('123').and_return(test)
91
- header "User-Agent", "some user agent"
92
102
  get "/test_runs/123/run/random/fake_test.html.file"
93
103
  last_response.body.should include("don't choose this one")
94
104
  end
@@ -98,7 +108,6 @@ module Spassky::Server
98
108
  it "returns the first file that ends with .html" do
99
109
  test = mock(:test, :name => "directory/test_name.html", :contents => @test_contents)
100
110
  TestRun.stub!(:find).with('123').and_return(test)
101
- header "User-Agent", "some user agent"
102
111
  get "/test_runs/123/run/random/not_a_file"
103
112
  last_response.body.should include("actual test!")
104
113
  end
@@ -136,6 +145,27 @@ module Spassky::Server
136
145
  @test_contents = {"file1" => "file1 contents", "file2" => "file2 contents"}
137
146
  end
138
147
 
148
+ context "no devices connected" do
149
+ before do
150
+ device_list.stub!(:recently_connected_devices).and_return([])
151
+ end
152
+
153
+ it "does not create a test run" do
154
+ TestRun.should_not_receive(:create)
155
+ post "/test_runs", { :name => "first-test", :contents => @test_contents.to_json }
156
+ end
157
+
158
+ it "halts with a 500" do
159
+ post "/test_runs", { :name => "first-test", :contents => @test_contents.to_json }
160
+ last_response.status.should == 500
161
+ end
162
+
163
+ it "displays the error" do
164
+ post "/test_runs", { :name => "first-test", :contents => @test_contents.to_json }
165
+ last_response.body.should == "There are no connected devices"
166
+ end
167
+ end
168
+
139
169
  it "creates a test run" do
140
170
  TestRun.should_receive(:create).with(:name => "first-test", :contents => @test_contents, :devices => ["foo", "bar"])
141
171
  post "/test_runs", { :name => "first-test", :contents => @test_contents.to_json }
@@ -0,0 +1,76 @@
1
+ require "spassky/server/device_database"
2
+ require "ostruct"
3
+ require "fakefs/safe"
4
+
5
+ module Spassky::Server
6
+ describe DeviceDatabase do
7
+ before do
8
+ WURFL.stub!(:new).and_return(nil)
9
+ RestClient.stub!(:get)
10
+ Kernel.stub!(:puts)
11
+ FakeFS.activate!
12
+ end
13
+
14
+ after do
15
+ FakeFS.deactivate!
16
+ end
17
+
18
+ context ".new" do
19
+ it "loads up the wurfl database" do
20
+ wurfl = mock(:wurfl).as_null_object
21
+ WURFL.should_receive(:new).with("wurfl/wurfl-latest.xml.gz").and_return(wurfl)
22
+ DeviceDatabase.new
23
+ end
24
+
25
+ it "tells the user that it is going to download a new wurfl database" do
26
+ Kernel.should_receive(:puts).with("Downloading WURFL database")
27
+ File.delete(Spassky::Server::WURFL_FILE)
28
+ DeviceDatabase.new
29
+ end
30
+
31
+ it "downloads a new wurfl database if it doesn't exist" do
32
+ File.delete(Spassky::Server::WURFL_FILE)
33
+ RestClient.should_receive(:get).with(Spassky::Server::LATEST).and_return("file content")
34
+ DeviceDatabase.new
35
+ File.read(Spassky::Server::WURFL_FILE).should == "file content"
36
+ end
37
+ end
38
+
39
+ describe ".device_identifier" do
40
+ subject { DeviceDatabase.new }
41
+
42
+ context "existing device" do
43
+ it "returns the device identifier" do
44
+ device = mock(:device)
45
+ device.stub!(:model_name).and_return "MODEL"
46
+ device.stub!(:id).and_return "ID"
47
+ device.stub!(:mobile_browser).and_return "BROWSER"
48
+ device.stub!(:device_os_version).and_return "OS_VERSION"
49
+ wurfl = mock(:wurfl)
50
+ wurfl.should_receive(:[]).and_return(device)
51
+ WURFL.should_receive(:new).and_return(wurfl)
52
+ subject.device_identifier("user agent").should == "MODEL (id = ID, mobile_browser = BROWSER, device_os_version = OS_VERSION)"
53
+ end
54
+ end
55
+
56
+ context "device deosn't exist in the database" do
57
+ it "returns user-agent" do
58
+ wurfl = mock(:wurfl)
59
+ wurfl.should_receive(:[]).and_return(nil)
60
+ WURFL.stub!(:new).and_return(wurfl)
61
+ subject.device_identifier("user agent").should == "user agent"
62
+ end
63
+ end
64
+ end
65
+
66
+ context "request device that exists" do
67
+ it "returns a device" do
68
+ wurfl = mock :wurfl
69
+ device = mock :device
70
+ wurfl.stub!(:[]).and_return(device)
71
+ WURFL.stub!(:new).and_return(wurfl)
72
+ DeviceDatabase.new.device("user agent").should == (device)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -3,30 +3,33 @@ require 'spassky/server/device_list'
3
3
 
4
4
  module Spassky::Server
5
5
  describe DeviceList do
6
+ subject { DeviceList.new }
7
+
8
+ it "doesn't blow up when I get the recently connected devices" do
9
+ subject.recently_connected_devices.should == []
10
+ end
11
+
6
12
  it "keeps track of when devices last connected" do
7
- list = DeviceList.new
8
- list.update_last_connected("foo")
9
- list.update_last_connected("bar")
10
- list.recently_connected_devices.should == ["foo", "bar"]
13
+ subject.update_last_connected("foo")
14
+ subject.update_last_connected("bar")
15
+ subject.recently_connected_devices.should == ["foo", "bar"]
11
16
  end
12
-
17
+
13
18
  it "clears all devices" do
14
- list = DeviceList.new
15
- list.update_last_connected("foo")
16
- list.update_last_connected("bar")
17
- list.clear
18
- list.recently_connected_devices.size.should == 0
19
+ subject.update_last_connected("foo")
20
+ subject.update_last_connected("bar")
21
+ subject.clear
22
+ subject.recently_connected_devices.size.should == 0
19
23
  end
20
-
24
+
21
25
  it "ignores devices connected more than 3 seconds ago" do
22
- list = DeviceList.new
23
26
  now = Time.now
24
27
  Time.stub!(:now).and_return(now - 3)
25
- list.update_last_connected("a")
28
+ subject.update_last_connected("a")
26
29
  Time.stub!(:now).and_return(now - 2)
27
- list.update_last_connected("b")
30
+ subject.update_last_connected("b")
28
31
  Time.stub!(:now).and_return(now)
29
- list.recently_connected_devices.should == ["b"]
32
+ subject.recently_connected_devices.should == ["b"]
30
33
  end
31
34
  end
32
- end
35
+ end
@@ -8,7 +8,7 @@ module Spassky
8
8
  TestResult.new([]).status.should == "in progress"
9
9
  end
10
10
  end
11
-
11
+
12
12
  context "when one device passes" do
13
13
  it "outputs a summary" do
14
14
  test_result = TestResult.new([
@@ -25,7 +25,7 @@ module Spassky
25
25
  Spassky::DeviceTestStatus.new('agent2', 'pass', 'test')
26
26
  ]).status.should == "pass"
27
27
  end
28
-
28
+
29
29
  it "outputs a pluralised summary" do
30
30
  test_result = TestResult.new([
31
31
  Spassky::DeviceTestStatus.new('agent1', 'pass', 'test'),
@@ -34,7 +34,7 @@ module Spassky
34
34
  test_result.summary.should == "1 test passed on 2 devices"
35
35
  end
36
36
  end
37
-
37
+
38
38
  context "when any device fails" do
39
39
  it "is a fail" do
40
40
  TestResult.new([
@@ -42,7 +42,7 @@ module Spassky
42
42
  Spassky::DeviceTestStatus.new('agent2', 'fail', 'test')
43
43
  ]).status.should == "fail"
44
44
  end
45
-
45
+
46
46
  it "outputs a summary" do
47
47
  test_result = TestResult.new([
48
48
  Spassky::DeviceTestStatus.new('agent1', 'fail', 'test')
@@ -50,7 +50,7 @@ module Spassky
50
50
  test_result.summary.should == "1 test failed on 1 device"
51
51
  end
52
52
  end
53
-
53
+
54
54
  context "when any test is still in progress" do
55
55
  it "is a fail" do
56
56
  TestResult.new([
@@ -60,7 +60,7 @@ module Spassky
60
60
  ]).status.should == "in progress"
61
61
  end
62
62
  end
63
-
63
+
64
64
  context "when 1 test times out" do
65
65
  it "outputs the correct summary" do
66
66
  test_result = TestResult.new([
@@ -68,7 +68,7 @@ module Spassky
68
68
  ])
69
69
  test_result.summary.should == "1 test timed out on 1 device"
70
70
  end
71
-
71
+
72
72
  it "has the status 'timed out'" do
73
73
  test_result = TestResult.new([
74
74
  Spassky::DeviceTestStatus.new('agent1', 'timed out', 'test'),
@@ -77,7 +77,7 @@ module Spassky
77
77
  test_result.status.should == "timed out"
78
78
  end
79
79
  end
80
-
80
+
81
81
  it "can be serialized and deserialized" do
82
82
  test_result = TestResult.new([Spassky::DeviceTestStatus.new('agent', 'pass', 'test')])
83
83
  json = test_result.to_json
@@ -86,7 +86,7 @@ module Spassky
86
86
  deserialized.device_statuses.first.user_agent.should == 'agent'
87
87
  deserialized.device_statuses.first.status.should == 'pass'
88
88
  end
89
-
89
+
90
90
  describe "#completed_since(nil)" do
91
91
  it "returns all device test results that are not in progress" do
92
92
  status_1 = Spassky::DeviceTestStatus.new('agent', 'pass', 'test1')
@@ -96,7 +96,7 @@ module Spassky
96
96
  test_result.completed_since(nil).should == [status_1, status_3]
97
97
  end
98
98
  end
99
-
99
+
100
100
  describe "#completed_since(other_test_result)" do
101
101
  it "returns all device test results that are no longer in progress" do
102
102
  status_a1 = Spassky::DeviceTestStatus.new('agent', 'pass', 'test1')
@@ -105,12 +105,12 @@ module Spassky
105
105
  status_b1 = Spassky::DeviceTestStatus.new('agent', 'pass', 'test1')
106
106
  status_b2 = Spassky::DeviceTestStatus.new('agent', 'fail', 'test2')
107
107
  status_b3 = Spassky::DeviceTestStatus.new('agent', 'timed out', 'test3')
108
-
108
+
109
109
  test_result_before = TestResult.new([status_a1, status_a2, status_a3])
110
110
  test_result_after = TestResult.new([status_b1, status_b2, status_b3])
111
-
111
+
112
112
  test_result_after.completed_since(test_result_before).should == [status_b2, status_b3]
113
113
  end
114
- end
114
+ end
115
115
  end
116
- end
116
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spassky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,12 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-18 00:00:00.000000000 +01:00
14
+ date: 2011-08-24 00:00:00.000000000 +01:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client
19
- requirement: &70262000987040 !ruby/object:Gem::Requirement
19
+ requirement: &70336540979360 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70262000987040
27
+ version_requirements: *70336540979360
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: json
30
- requirement: &70262000986620 !ruby/object:Gem::Requirement
30
+ requirement: &70336540978940 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70262000986620
38
+ version_requirements: *70336540978940
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: sinatra
41
- requirement: &70262000986200 !ruby/object:Gem::Requirement
41
+ requirement: &70336540978520 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70262000986200
49
+ version_requirements: *70336540978520
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rainbow
52
- requirement: &70262000985780 !ruby/object:Gem::Requirement
52
+ requirement: &70336540978100 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,21 @@ dependencies:
57
57
  version: '0'
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *70262000985780
60
+ version_requirements: *70336540978100
61
+ - !ruby/object:Gem::Dependency
62
+ name: wurfl-lite
63
+ requirement: &70336540977680 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :runtime
70
+ prerelease: false
71
+ version_requirements: *70336540977680
61
72
  - !ruby/object:Gem::Dependency
62
73
  name: rake
63
- requirement: &70262000985360 !ruby/object:Gem::Requirement
74
+ requirement: &70336540977260 !ruby/object:Gem::Requirement
64
75
  none: false
65
76
  requirements:
66
77
  - - ! '>='
@@ -68,10 +79,10 @@ dependencies:
68
79
  version: '0'
69
80
  type: :development
70
81
  prerelease: false
71
- version_requirements: *70262000985360
82
+ version_requirements: *70336540977260
72
83
  - !ruby/object:Gem::Dependency
73
84
  name: rspec
74
- requirement: &70262000984940 !ruby/object:Gem::Requirement
85
+ requirement: &70336546051000 !ruby/object:Gem::Requirement
75
86
  none: false
76
87
  requirements:
77
88
  - - ! '>='
@@ -79,10 +90,10 @@ dependencies:
79
90
  version: '0'
80
91
  type: :development
81
92
  prerelease: false
82
- version_requirements: *70262000984940
93
+ version_requirements: *70336546051000
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: cucumber
85
- requirement: &70262000984520 !ruby/object:Gem::Requirement
96
+ requirement: &70336546050580 !ruby/object:Gem::Requirement
86
97
  none: false
87
98
  requirements:
88
99
  - - ! '>='
@@ -90,10 +101,10 @@ dependencies:
90
101
  version: '0'
91
102
  type: :development
92
103
  prerelease: false
93
- version_requirements: *70262000984520
104
+ version_requirements: *70336546050580
94
105
  - !ruby/object:Gem::Dependency
95
106
  name: capybara
96
- requirement: &70262000984100 !ruby/object:Gem::Requirement
107
+ requirement: &70336546050160 !ruby/object:Gem::Requirement
97
108
  none: false
98
109
  requirements:
99
110
  - - ! '>='
@@ -101,10 +112,21 @@ dependencies:
101
112
  version: '0'
102
113
  type: :development
103
114
  prerelease: false
104
- version_requirements: *70262000984100
115
+ version_requirements: *70336546050160
105
116
  - !ruby/object:Gem::Dependency
106
117
  name: aruba
107
- requirement: &70262000983680 !ruby/object:Gem::Requirement
118
+ requirement: &70336546049740 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: *70336546049740
127
+ - !ruby/object:Gem::Dependency
128
+ name: fakefs
129
+ requirement: &70336546049320 !ruby/object:Gem::Requirement
108
130
  none: false
109
131
  requirements:
110
132
  - - ! '>='
@@ -112,7 +134,7 @@ dependencies:
112
134
  version: '0'
113
135
  type: :development
114
136
  prerelease: false
115
- version_requirements: *70262000983680
137
+ version_requirements: *70336546049320
116
138
  description: ''
117
139
  email:
118
140
  - andrew.vos@gmail.com
@@ -132,8 +154,15 @@ files:
132
154
  - bin/spassky
133
155
  - bin/spassky-server
134
156
  - config.ru
157
+ - examples/qunit-failing/main.js
158
+ - examples/qunit-failing/qunit.js
159
+ - examples/qunit-failing/suite.html
160
+ - examples/qunit-passing/main.js
161
+ - examples/qunit-passing/qunit.js
162
+ - examples/qunit-passing/suite.html
135
163
  - features/connection.feature
136
164
  - features/device_timeout.feature
165
+ - features/list_devices.feature
137
166
  - features/run_html_tests.feature
138
167
  - features/run_qunit_tests.feature
139
168
  - features/server.feature
@@ -143,6 +172,7 @@ files:
143
172
  - lib/spassky.rb
144
173
  - lib/spassky/client.rb
145
174
  - lib/spassky/client/cli.rb
175
+ - lib/spassky/client/device_list_retriever.rb
146
176
  - lib/spassky/client/directory_reader.rb
147
177
  - lib/spassky/client/pusher.rb
148
178
  - lib/spassky/client/test_runner.rb
@@ -150,6 +180,7 @@ files:
150
180
  - lib/spassky/server.rb
151
181
  - lib/spassky/server/app.rb
152
182
  - lib/spassky/server/assert.js
183
+ - lib/spassky/server/device_database.rb
153
184
  - lib/spassky/server/device_list.rb
154
185
  - lib/spassky/server/html_test.rb
155
186
  - lib/spassky/server/random_string_generator.rb
@@ -158,11 +189,13 @@ files:
158
189
  - lib/spassky/version.rb
159
190
  - spassky.gemspec
160
191
  - spec/spassky/client/cli_spec.rb
192
+ - spec/spassky/client/device_list_retriever_spec.rb
161
193
  - spec/spassky/client/directory_reader_spec.rb
162
194
  - spec/spassky/client/pusher_spec.rb
163
195
  - spec/spassky/client/test_runner_spec.rb
164
196
  - spec/spassky/client/writer_spec.rb
165
197
  - spec/spassky/server/app_spec.rb
198
+ - spec/spassky/server/device_database_spec.rb
166
199
  - spec/spassky/server/device_list_spec.rb
167
200
  - spec/spassky/server/random_string_generator_spec.rb
168
201
  - spec/spassky/server/test_run_spec.rb
@@ -196,6 +229,7 @@ summary: ''
196
229
  test_files:
197
230
  - features/connection.feature
198
231
  - features/device_timeout.feature
232
+ - features/list_devices.feature
199
233
  - features/run_html_tests.feature
200
234
  - features/run_qunit_tests.feature
201
235
  - features/server.feature
@@ -203,11 +237,13 @@ test_files:
203
237
  - features/support/env.rb
204
238
  - features/support/fixtures/qunit.js
205
239
  - spec/spassky/client/cli_spec.rb
240
+ - spec/spassky/client/device_list_retriever_spec.rb
206
241
  - spec/spassky/client/directory_reader_spec.rb
207
242
  - spec/spassky/client/pusher_spec.rb
208
243
  - spec/spassky/client/test_runner_spec.rb
209
244
  - spec/spassky/client/writer_spec.rb
210
245
  - spec/spassky/server/app_spec.rb
246
+ - spec/spassky/server/device_database_spec.rb
211
247
  - spec/spassky/server/device_list_spec.rb
212
248
  - spec/spassky/server/random_string_generator_spec.rb
213
249
  - spec/spassky/server/test_run_spec.rb