testbot 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../../../lib/shared/adapters/helpers/ruby_env.rb'))
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'flexmock/test_unit'
5
+
6
+ class RubyEnvTest < Test::Unit::TestCase
7
+
8
+ context "self.bundler?" do
9
+
10
+ should "return true if bundler is installed and there is a Gemfile" do
11
+ flexmock(Gem).should_receive(:available?).with("bundler").once.and_return(true)
12
+ flexmock(File).should_receive(:exists?).with("path/to/project/Gemfile").once.and_return(true)
13
+ assert_equal true, RubyEnv.bundler?("path/to/project")
14
+ end
15
+
16
+ should "return false if bundler is installed but there is no Gemfile" do
17
+ flexmock(Gem).should_receive(:available?).with("bundler").once.and_return(true)
18
+ flexmock(File).should_receive(:exists?).and_return(false)
19
+ assert_equal false, RubyEnv.bundler?("path/to/project")
20
+ end
21
+
22
+ should "return false if bundler is not installed" do
23
+ flexmock(Gem).should_receive(:available?).with("bundler").once.and_return(false)
24
+ assert_equal false, RubyEnv.bundler?("path/to/project")
25
+ end
26
+
27
+ end
28
+
29
+ context "self.ruby_command" do
30
+
31
+ should "use ruby by default" do
32
+ flexmock(RubyEnv).should_receive(:bundler?).and_return(false)
33
+ flexmock(File).should_receive(:exists?).and_return(false)
34
+ assert_equal 'ruby -S rspec', RubyEnv.ruby_command("path/to/project", :script => "script/spec", :bin => "rspec")
35
+ end
36
+
37
+ should "use bundler when available and use the binary when there is no script" do
38
+ flexmock(RubyEnv).should_receive(:bundler?).once.with("path/to/project").and_return(true)
39
+ flexmock(File).should_receive(:exists?).with("path/to/project/script/spec").and_return(false)
40
+ assert_equal 'ruby -S bundle exec rspec', RubyEnv.ruby_command("path/to/project", :script => "script/spec", :bin => "rspec")
41
+ end
42
+
43
+ should "use the script when it exists when using bundler" do
44
+ flexmock(RubyEnv).should_receive(:bundler?).and_return(true)
45
+ flexmock(File).should_receive(:exists?).and_return(true)
46
+ assert_equal 'ruby -S bundle exec script/spec', RubyEnv.ruby_command("path/to/project", :script => "script/spec", :bin => "rspec")
47
+ end
48
+
49
+ should "use the script when it exists when not using bundler" do
50
+ flexmock(RubyEnv).should_receive(:bundler?).and_return(false)
51
+ flexmock(File).should_receive(:exists?).and_return(true)
52
+ assert_equal 'ruby -S script/spec', RubyEnv.ruby_command("path/to/project", :script => "script/spec", :bin => "rspec")
53
+ end
54
+
55
+ should "be able to use jruby" do
56
+ flexmock(RubyEnv).should_receive(:bundler?).and_return(false)
57
+ flexmock(File).should_receive(:exists?).and_return(true)
58
+ assert_equal 'jruby -S script/spec', RubyEnv.ruby_command("path/to/project", :script => "script/spec",
59
+ :bin => "rspec", :ruby_interpeter => "jruby")
60
+ end
61
+
62
+ should "be able to use jruby with bundler" do
63
+ flexmock(RubyEnv).should_receive(:bundler?).and_return(true)
64
+ flexmock(File).should_receive(:exists?).and_return(true)
65
+ assert_equal 'jruby -S bundle exec script/spec', RubyEnv.ruby_command("path/to/project", :script => "script/spec",
66
+ :bin => "rspec", :ruby_interpeter => "jruby")
67
+ end
68
+
69
+ should "use the interpeter when there is no binary specified" do
70
+ flexmock(RubyEnv).should_receive(:bundler?).and_return(true)
71
+ flexmock(File).should_receive(:exists?).and_return(false)
72
+ assert_equal 'ruby -S bundle exec ruby', RubyEnv.ruby_command("path/to/project")
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/shared/adapters/adapter.rb'))
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ class AdapterTest < Test::Unit::TestCase
6
+
7
+ should "be able to find the adapters" do
8
+ assert_equal RSpecAdapter, Adapter.find(:spec)
9
+ assert_equal CucumberAdapter, Adapter.find(:features)
10
+ assert_equal TestUnitAdapter, Adapter.find(:test)
11
+ end
12
+
13
+ should "find be able to find an adapter by string" do
14
+ assert_equal RSpecAdapter, Adapter.find("spec")
15
+ end
16
+
17
+ should "return be able to all types" do
18
+ assert_equal [ RSpecAdapter, CucumberAdapter, TestUnitAdapter ], Adapter.all
19
+ end
20
+
21
+ end
@@ -0,0 +1,185 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../lib/shared/testbot')) unless defined?(Testbot)
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'flexmock/test_unit'
5
+ require 'sinatra'
6
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../lib/requester/requester'))
7
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../lib/server/server'))
8
+
9
+ module Testbot
10
+
11
+ module TestHelpers
12
+
13
+ def requester_attributes
14
+ { :server_host => "192.168.0.100",
15
+ :rsync_path => nil,
16
+ :rsync_ignores => '', :server_user => nil, :available_runner_usage => nil,
17
+ :project => nil, :ssh_tunnel => nil }
18
+ end
19
+
20
+ end
21
+
22
+ class CLITest < Test::Unit::TestCase
23
+
24
+ include TestHelpers
25
+
26
+ context "self.run" do
27
+
28
+ context "with no args" do
29
+ should "return false" do
30
+ assert_equal false, CLI.run([])
31
+ end
32
+ end
33
+
34
+ context "with --help" do
35
+ should "return false" do
36
+ assert_equal false, CLI.run([ '--help' ])
37
+ end
38
+ end
39
+
40
+ context "with --version" do
41
+ should "print version and return true" do
42
+ flexmock(CLI).should_receive(:puts).once.with("Testbot #{Testbot.version}")
43
+ assert_equal true, CLI.run([ '--version' ])
44
+ end
45
+ end
46
+
47
+ context "with --server" do
48
+ should "start a server" do
49
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::SERVER_PID)
50
+ flexmock(SimpleDaemonize).should_receive(:start).once.with(any, Testbot::SERVER_PID, "testbot (server)")
51
+ flexmock(CLI).should_receive(:puts).once.with("Testbot server started (pid: #{Process.pid})")
52
+ assert_equal true, CLI.run([ "--server" ])
53
+ end
54
+
55
+ should "start a server when start is passed" do
56
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::SERVER_PID)
57
+ flexmock(SimpleDaemonize).should_receive(:start).once
58
+ flexmock(CLI).should_receive(:puts)
59
+ assert_equal true, CLI.run([ "--server", "start" ])
60
+ end
61
+
62
+ should "stop a server when stop is passed" do
63
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::SERVER_PID).and_return(true)
64
+ flexmock(CLI).should_receive(:puts).once.with("Testbot server stopped")
65
+ assert_equal true, CLI.run([ "--server", "stop" ])
66
+ end
67
+
68
+ should "not print when SimpleDaemonize.stop returns false" do
69
+ flexmock(SimpleDaemonize).should_receive(:stop).and_return(false)
70
+ flexmock(CLI).should_receive(:puts).never
71
+ CLI.run([ "--stop", "server" ])
72
+ end
73
+
74
+ should "start it in the foreground with run" do
75
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::SERVER_PID)
76
+ flexmock(SimpleDaemonize).should_receive(:start).never
77
+ flexmock(Sinatra::Application).should_receive(:run!).once.with(:environment => "production")
78
+ assert_equal true, CLI.run([ "--server", 'run' ])
79
+ end
80
+ end
81
+
82
+ context "with --runner" do
83
+ should "start a runner" do
84
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::RUNNER_PID)
85
+ flexmock(SimpleDaemonize).should_receive(:start).once.with(any, Testbot::RUNNER_PID, "testbot (runner)")
86
+ flexmock(CLI).should_receive(:puts).once.with("Testbot runner started (pid: #{Process.pid})")
87
+ assert_equal true, CLI.run([ "--runner", "--connect", "192.168.0.100", "--working_dir", "/tmp/testbot" ])
88
+ end
89
+
90
+ should "start a runner when start is passed" do
91
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::RUNNER_PID)
92
+ flexmock(SimpleDaemonize).should_receive(:start).once
93
+ flexmock(CLI).should_receive(:puts)
94
+ assert_equal true, CLI.run([ "--runner", "start", "--connect", "192.168.0.100" ])
95
+ end
96
+
97
+ should "stop a runner when stop is passed" do
98
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::RUNNER_PID).and_return(true)
99
+ flexmock(CLI).should_receive(:puts).once.with("Testbot runner stopped")
100
+ assert_equal true, CLI.run([ "--runner", "stop" ])
101
+ end
102
+
103
+ should "return false without connect" do
104
+ assert_equal false, CLI.run([ "--runner", "--connect" ])
105
+ assert_equal false, CLI.run([ "--runner" ])
106
+ end
107
+
108
+ should "start it in the foreground with run" do
109
+ flexmock(SimpleDaemonize).should_receive(:stop).once.with(Testbot::RUNNER_PID)
110
+ flexmock(SimpleDaemonize).should_receive(:start).never
111
+ flexmock(Runner::Runner).should_receive(:new).once.and_return(mock = Object.new)
112
+ flexmock(mock).should_receive(:run!).once
113
+ assert_equal true, CLI.run([ "--runner", 'run', '--connect', '192.168.0.100' ])
114
+ end
115
+ end
116
+
117
+ Adapter.all.each do |adapter|
118
+ context "with --#{adapter.type}" do
119
+ should "start a #{adapter.name} requester and return true" do
120
+ flexmock(Requester::Requester).should_receive(:new).once.
121
+ with(requester_attributes).and_return(mock = Object.new)
122
+ flexmock(mock).should_receive(:run_tests).once.with(adapter, adapter.base_path)
123
+ assert_equal true, CLI.run([ "--#{adapter.type}", "--connect", "192.168.0.100" ])
124
+ end
125
+
126
+ should "accept a custom rsync_path" do
127
+ flexmock(Requester::Requester).should_receive(:new).once.
128
+ with(requester_attributes.merge({ :rsync_path => "/somewhere/else" })).
129
+ and_return(mock = Object.new)
130
+ flexmock(mock).should_receive(:run_tests)
131
+ CLI.run([ "--#{adapter.type}", "--connect", "192.168.0.100", '--rsync_path', '/somewhere/else' ])
132
+ end
133
+
134
+ should "accept rsync_ignores" do
135
+ flexmock(Requester::Requester).should_receive(:new).once.
136
+ with(requester_attributes.merge({ :rsync_ignores => "tmp log" })).
137
+ and_return(mock = Object.new)
138
+ flexmock(mock).should_receive(:run_tests)
139
+ CLI.run([ "--#{adapter.type}", "--connect", "192.168.0.100", '--rsync_ignores', 'tmp', 'log' ])
140
+ end
141
+
142
+ should "accept ssh tunnel" do
143
+ flexmock(Requester::Requester).should_receive(:new).once.
144
+ with(requester_attributes.merge({ :ssh_tunnel => true })).
145
+ and_return(mock = Object.new)
146
+ flexmock(mock).should_receive(:run_tests)
147
+ CLI.run([ "--#{adapter.type}", "--connect", "192.168.0.100", '--ssh_tunnel' ])
148
+ end
149
+
150
+ should "accept a custom user" do
151
+ flexmock(Requester::Requester).should_receive(:new).once.
152
+ with(requester_attributes.merge({ :server_user => "cruise" })).
153
+ and_return(mock = Object.new)
154
+ flexmock(mock).should_receive(:run_tests)
155
+ CLI.run([ "--#{adapter.type}", "--connect", "192.168.0.100", '--user', 'cruise' ])
156
+ end
157
+
158
+ should "accept a custom project name" do
159
+ flexmock(Requester::Requester).should_receive(:new).once.
160
+ with(requester_attributes.merge({ :project => "rspec" })).
161
+ and_return(mock = Object.new)
162
+ flexmock(mock).should_receive(:run_tests)
163
+ CLI.run([ "--#{adapter.type}", "--connect", "192.168.0.100", '--project', 'rspec' ])
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ context "self.parse_args" do
170
+
171
+ should 'convert ARGV arguments to a hash' do
172
+ hash = CLI.parse_args("--runner --connect http://127.0.0.1:#{Testbot::SERVER_PORT} --working_dir ~/testbot --ssh_tunnel user@testbot_server".split)
173
+ assert_equal ({ :runner => true, :connect => "http://127.0.0.1:#{Testbot::SERVER_PORT}", :working_dir => "~/testbot", :ssh_tunnel => "user@testbot_server" }), hash
174
+ end
175
+
176
+ should "handle just a key without a value" do
177
+ hash = CLI.parse_args([ "--server" ])
178
+ assert_equal ({ :server => true }), hash
179
+ end
180
+
181
+ end
182
+
183
+ end
184
+
185
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'fileutils'
4
+ require 'shoulda'
5
+
6
+ class IntegrationTest < Test::Unit::TestCase
7
+
8
+ def stop!
9
+ system "export INTEGRATION_TEST=true; bin/testbot --server stop > /dev/null"
10
+ system "export INTEGRATION_TEST=true; bin/testbot --runner stop > /dev/null"
11
+ end
12
+
13
+ # This is slow, and Test:Unit does not have "before/after :all" method, so I'm using a single testcase for multiple tests
14
+ should "be able to send a build request, have it run and show the results" do
15
+ Thread.new {
16
+
17
+ sleep 30
18
+ puts "Still running after 30 secs, stopping..."
19
+ stop!
20
+ }
21
+
22
+ system "rm -rf tmp; mkdir -p tmp; cp -rf test/fixtures/local tmp/local"
23
+ system "export INTEGRATION_TEST=true; bin/testbot --runner --connect 127.0.0.1 --working_dir tmp/runner > /dev/null"
24
+ system "export INTEGRATION_TEST=true; bin/testbot --server > /dev/null"
25
+
26
+ # For debug
27
+ # Thread.new do
28
+ # system "export INTEGRATION_TEST=true; bin/testbot --runner run --connect 127.0.0.1 --working_dir tmp/runner"
29
+ # end
30
+ # Thread.new do
31
+ # system "export INTEGRATION_TEST=true; bin/testbot --server run"
32
+ # end
33
+
34
+ sleep 2.0
35
+ result = `cd tmp/local; INTEGRATION_TEST=true ../../bin/testbot --spec --connect 127.0.0.1 --rsync_path ../server --rsync_ignores "log/* tmp/*"`
36
+
37
+ # Should include the result from script/spec
38
+ #puts result.inspect
39
+ assert result.include?('script/spec got called with ["-O", "spec/spec.opts", "spec/models/house_spec.rb", "spec/models/car_spec.rb"]') ||
40
+ result.include?('script/spec got called with ["-O", "spec/spec.opts", "spec/models/car_spec.rb", "spec/models/house_spec.rb"]')
41
+
42
+
43
+ # Should not include ignored files
44
+ assert !File.exists?("tmp/server/log/test.log")
45
+ assert !File.exists?("tmp/server/tmp/restart.txt")
46
+ assert !File.exists?("tmp/runner/local/log/test.log")
47
+ assert !File.exists?("tmp/runner/local/tmp/restart.txt")
48
+ end
49
+
50
+ def teardown
51
+ stop!
52
+ FileUtils.rm_rf "tmp"
53
+ end
54
+
55
+ end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.description = %q{Testbot is a test distribution tool that works with Rails, RSpec, Test::Unit and Cucumber.}
12
12
  s.bindir = "bin"
13
13
  s.executables = [ "testbot" ]
14
- s.files = Dir.glob("lib/**/*") + %w(Gemfile .gemtest testbot.gemspec CHANGELOG README.markdown bin/testbot) +
14
+ s.files = Dir.glob("lib/**/*") + Dir.glob("test/**/*") + %w(Gemfile .gemtest Rakefile testbot.gemspec CHANGELOG README.markdown bin/testbot) +
15
15
  (File.exists?("DEV_VERSION") ? [ "DEV_VERSION" ] : [])
16
16
  s.add_dependency('sinatra', '=1.0.0') # To be able to use rack 1.0.1 which is compatible with rails 2.
17
17
  s.add_dependency('httparty', '>= 0.6.1')
@@ -27,5 +27,6 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency("cucumber")
28
28
  s.add_development_dependency("rvm")
29
29
  s.add_development_dependency("rake")
30
+ s.add_development_dependency("bundler")
30
31
  end
31
32
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testbot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Joakim Kolsj\xC3\xB6"
@@ -212,6 +212,20 @@ dependencies:
212
212
  version: "0"
213
213
  type: :development
214
214
  version_requirements: *id013
215
+ - !ruby/object:Gem::Dependency
216
+ name: bundler
217
+ prerelease: false
218
+ requirement: &id014 !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ hash: 3
224
+ segments:
225
+ - 0
226
+ version: "0"
227
+ type: :development
228
+ version_requirements: *id014
215
229
  description: Testbot is a test distribution tool that works with Rails, RSpec, Test::Unit and Cucumber.
216
230
  email:
217
231
  - joakim.kolsjo@gmail.com
@@ -249,8 +263,25 @@ files:
249
263
  - lib/shared/testbot.rb
250
264
  - lib/tasks/testbot.rake
251
265
  - lib/testbot.rb
266
+ - test/fixtures/local/config/testbot.yml
267
+ - test/fixtures/local/log/test.log
268
+ - test/fixtures/local/Rakefile
269
+ - test/fixtures/local/script/spec
270
+ - test/fixtures/local/spec/models/car_spec.rb
271
+ - test/fixtures/local/spec/models/house_spec.rb
272
+ - test/fixtures/local/spec/spec.opts
273
+ - test/fixtures/local/tmp/restart.txt
274
+ - test/requester/test_requester.rb
275
+ - test/runner/test_job.rb
276
+ - test/server/test_group.rb
277
+ - test/server/test_server.rb
278
+ - test/shared/adapters/helpers/test_ruby_env.rb
279
+ - test/shared/adapters/test_adapter.rb
280
+ - test/shared/test_testbot.rb
281
+ - test/test_integration.rb
252
282
  - Gemfile
253
283
  - .gemtest
284
+ - Rakefile
254
285
  - testbot.gemspec
255
286
  - CHANGELOG
256
287
  - README.markdown