tdd_deploy 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require 'tdd_deploy/base'
2
+
3
+ module TddDeploy
4
+ # == TddDeploy::SmokeTest
5
+ #
6
+ # TddDeploy::SmokeTest is a local test for TddDeploy.
7
+ #
8
+ # it's used to test the testing framework and contains two trivial tests:
9
+ #
10
+ # * return_true
11
+ # * smoke
12
+ class SmokeTest < TddDeploy::Base
13
+
14
+ # returns true
15
+ def return_true
16
+ true
17
+ end
18
+
19
+ # returns true
20
+ def smoke
21
+ true
22
+ end
23
+ end
24
+ end
@@ -16,18 +16,35 @@ module TddDeploy
16
16
  LOCAL_TESTS_DIR = File.join(Dir.pwd, 'lib', 'tdd_deploy', 'local_tests')
17
17
  TEMPLATE_PATH = File.join(LIB_DIR, 'tdd_deploy', 'server-templates', 'test_results.html.erb')
18
18
 
19
- attr_accessor :test_classes, :query_hash, :failed_tests
19
+ attr_accessor :test_classes, :query_hash
20
20
 
21
- # accepts env_hash arguments. It's just as easy to instantiate and then change
22
- # the variables using self.set_env
23
21
  def initialize *args
24
- @already_defined = TddDeploy.constants
22
+ raise RuntimeError.new("No Environment File") unless File.exists? TddDeploy::Environ::ENV_FNAME
23
+ super
25
24
  load_all_tests
26
- if args.last.is_a? Hash
27
- self.set_env args.last
28
- self.save_env
25
+ end
26
+
27
+ # failed_tests returns a unique, sorted list of strings. It just seemed easier to
28
+ # do it in the accessors than take the chance of using push, pop, etc and mucking it
29
+ # up - like I did before.
30
+ def failed_tests
31
+ @failed_tests ||= []
32
+ raise RuntimeError.new("@failed_tests is not an Array: #{@failed_tests.inspect}") unless @failed_tests.is_a? Array
33
+ @failed_tests = @failed_tests.map { |x| x.to_s }.uniq.sort
34
+ end
35
+
36
+ # failed_tests= does the right thing for all kinds of input variations.
37
+ def failed_tests=(value)
38
+ begin
39
+ value = value.split(/[\s,]+/) if value.is_a? String
40
+ value = [value] unless value.is_a? Array
41
+
42
+ @failed_tests = @failed_tests.to_a unless @failed_tests.is_a? Array
43
+
44
+ @failed_tests = (@failed_tests + value.map { |x| x.to_s }).uniq
45
+ rescue
46
+ @failed_tests = (@failed_tests.to_a.map { |x| x.to_s } + value.to_a.map { |x| x.to_s }).uniq.sort
29
47
  end
30
- super
31
48
  end
32
49
 
33
50
  # rack interface. takes an env Hash and returns [code, headers, body]
@@ -39,6 +56,8 @@ module TddDeploy
39
56
  configurator = TddDeploy::Configurator.new
40
57
  configurator.make_configuration_files
41
58
  end
59
+
60
+ load_all_tests
42
61
 
43
62
  if query_hash['failed-tests']
44
63
  remove_failed_tests
@@ -62,7 +81,7 @@ module TddDeploy
62
81
  [TddDeploy::Server::HOST_TESTS_DIR, TddDeploy::Server::SITE_TESTS_DIR,
63
82
  TddDeploy::Server::LOCAL_TESTS_DIR].each do |dir|
64
83
  if File.exists?(dir)
65
- puts "gathering tests from #{dir}"
84
+ # puts "gathering tests from #{dir}"
66
85
  Dir.new(dir).each do |fname|
67
86
  next if fname[0] == '.'
68
87
 
@@ -89,7 +108,7 @@ module TddDeploy
89
108
  reset_tests
90
109
 
91
110
  ret = true
92
- @failed_tests = []
111
+ self.failed_tests = []
93
112
  self.test_classes.each do |klass|
94
113
  ret &= run_all_tests_in_class(klass)
95
114
  end
@@ -101,6 +120,7 @@ module TddDeploy
101
120
  read_env
102
121
  ret = true
103
122
  test_list = test_list.split(/[\s,]+/) if test_list.is_a? String
123
+ self.failed_tests -= test_list
104
124
  test_list.each do |test|
105
125
  ret &= run_a_test test
106
126
  end
@@ -109,7 +129,7 @@ module TddDeploy
109
129
 
110
130
  private
111
131
 
112
- # not presently used
132
+ # used by
113
133
  def run_all_tests_in_class klass
114
134
  read_env
115
135
  obj = klass.new
@@ -117,17 +137,17 @@ module TddDeploy
117
137
  # puts "#{klass}.instance_methods: #{klass.instance_methods(false)}"
118
138
  klass.instance_methods(false).each do |func|
119
139
  test_result = obj.send func.to_sym
120
- @failed_tests.push(func) unless test_result
140
+ self.failed_tests.push(func) unless test_result
121
141
  ret &= test_result
122
142
  end
123
143
  ret
124
144
  end
125
145
 
126
146
  def run_a_test test
127
- read_env
128
- obj = @test_to_class_map[test].new
147
+ return false unless (klass = @test_to_class_map[test])
148
+ obj = klass.new
129
149
  test_result = obj.send test.to_sym
130
- @failed_tests.push(test) unless test_result
150
+ self.failed_tests.push(test) unless test_result
131
151
  test_result
132
152
  end
133
153
 
@@ -145,7 +165,7 @@ module TddDeploy
145
165
  end
146
166
 
147
167
  def new_query_string
148
- str = "failed-tests=" + URI.escape(@failed_tests.join(',')) unless @failed_tests.nil? || @failed_tests.empty?
168
+ "failed-tests=" + URI.escape(self.failed_tests.join(',')) unless @failed_tests.empty?
149
169
  end
150
170
 
151
171
  end
@@ -1,3 +1,3 @@
1
1
  module TddDeploy
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
data/tests/test_server.rb CHANGED
@@ -1,16 +1,21 @@
1
1
  $:.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
3
  require 'test/unit'
4
- require 'tdd_deploy/run_methods'
4
+ require 'tdd_deploy/environ'
5
+ require 'tdd_deploy/server'
5
6
 
6
7
  class TestServerTestCase < Test::Unit::TestCase
7
8
  GEM_ROOT = File.expand_path('../..', __FILE__)
8
9
  BIN_DIR = File.join(GEM_ROOT, 'bin')
9
10
 
10
- include TddDeploy::RunMethods
11
+ include TddDeploy::Environ
11
12
 
12
13
  def setup
13
- require 'tdd_deploy/server'
14
+ # we can't create a server w/o an environment, but we flush it between tests.
15
+ # so we have to create the enviornment file here
16
+ self.reset_env
17
+ self.save_env
18
+
14
19
  @tester = TddDeploy::Server.new
15
20
  @tester.set_env(:web_hosts => 'arch', :db_hosts => 'arch',
16
21
  :host_admin => 'mike', :local_admin => 'mike', :ssh_timeout => 2,
@@ -20,7 +25,14 @@ class TestServerTestCase < Test::Unit::TestCase
20
25
 
21
26
  def teardown
22
27
  @tester = nil
23
- system('rm site_host_setup.env')
28
+ system('rm -f site_host_setup.env')
29
+ end
30
+
31
+ def test_env_file_detection
32
+ File.unlink TddDeploy::Environ::ENV_FNAME
33
+ assert_raises RuntimeError do
34
+ TddDeploy::Server.new
35
+ end
24
36
  end
25
37
 
26
38
  def test_classes_array
@@ -35,7 +47,50 @@ class TestServerTestCase < Test::Unit::TestCase
35
47
  assert ret, "@tester should run all tests and return true: returned: #{ret.inspect}: #{failures}"
36
48
  # puts @tester.formatted_test_results
37
49
  end
50
+
51
+ def test_run_a_test
52
+ assert @tester.send(:run_a_test, 'return_true'), "return_true should pass"
53
+ end
54
+
55
+ def test_run_some_tests
56
+ assert @tester.send(:run_selected_tests, 'return_true,smoke'), 'run_selected_tests should work with a string'
57
+ assert @tester.send(:run_selected_tests, ['return_true', 'smoke']), 'run_selected_tests can run two tests'
58
+ end
38
59
 
60
+ def test_parse_query_string
61
+ qs = @tester.send :parse_query_string, "foo=bar&bar=some%20stuff"
62
+ assert_equal 2, qs.length, "query string should have to entries"
63
+ assert_equal 'bar', qs['foo'], "qs['foo'] should be 'bar'"
64
+ assert_equal 'some stuff', qs['bar'], "qs['bar'] should be 'some stuff'"
65
+ end
66
+
67
+ def test_failed_tests
68
+ assert @tester.failed_tests.is_a?(Array), "failed_tests is an Array"
69
+ @tester.failed_tests = :foo
70
+ assert_equal ['foo'], @tester.failed_tests, "can assign symbol to failed_tests"
71
+ @tester.failed_tests = 'foo'
72
+ assert_equal ['foo'], @tester.failed_tests, "can assign String to failed_tests"
73
+ @tester.failed_tests = ['foo', 'bar']
74
+ assert_equal ['bar','foo'], @tester.failed_tests, "can assign Array of Strings to failed_tests"
75
+ @tester.failed_tests = ['foo', :bar]
76
+ assert_equal ['bar', 'foo'], @tester.failed_tests, "can assign Array of Strings and symbols to failed_tests"
77
+ @tester.failed_tests.push('baz')
78
+ assert_equal ['bar', 'baz', 'foo'], @tester.failed_tests, "pushing string should work"
79
+ @tester.failed_tests.push(:snort)
80
+ assert_equal ['bar', 'baz', 'foo', 'snort'], @tester.failed_tests, "pushing symbol should work"
81
+ @tester.failed_tests.push('foo')
82
+ assert_equal ['bar', 'baz', 'foo', 'snort'], @tester.failed_tests, "pushing duplicate should not add entry"
83
+ end
84
+
85
+ def test_new_query_string
86
+ @tester.failed_tests = [:foo, :bar, :baz]
87
+ assert_equal 'failed-tests=bar,baz,foo', @tester.send(:new_query_string), "new query string should be correct"
88
+ end
89
+
90
+ def test_render_results
91
+ assert_match /Test Results/, @tester.send(:render_results), "render results should return a page"
92
+ end
93
+
39
94
  def test_rack_interface
40
95
  code, headers, body = @tester.call({})
41
96
  assert_equal 200, code, "@tester always responds with 200"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdd_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2153409860 !ruby/object:Gem::Requirement
16
+ requirement: &2153409660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153409860
24
+ version_requirements: *2153409660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: net-ping
27
- requirement: &2153409060 !ruby/object:Gem::Requirement
27
+ requirement: &2153409040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153409060
35
+ version_requirements: *2153409040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: net-ssh
38
- requirement: &2153397720 !ruby/object:Gem::Requirement
38
+ requirement: &2153397700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153397720
46
+ version_requirements: *2153397700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ZenTest
49
- requirement: &2153397080 !ruby/object:Gem::Requirement
49
+ requirement: &2153397060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 4.5.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153397080
57
+ version_requirements: *2153397060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: autotest-growl
60
- requirement: &2153396520 !ruby/object:Gem::Requirement
60
+ requirement: &2153396500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153396520
68
+ version_requirements: *2153396500
69
69
  description: Test driven support for host provisioning & Capistrano deployment - for
70
70
  those who don't want to bother learning too much
71
71
  email: ! ' mike@clove.com '
@@ -92,6 +92,7 @@ files:
92
92
  - lib/tdd_deploy/host_tests/remote_nginx.rb
93
93
  - lib/tdd_deploy/host_tests/remote_postfix.rb
94
94
  - lib/tdd_deploy/host_tests/remote_postgresql.rb
95
+ - lib/tdd_deploy/local_tests/smoke_test.rb
95
96
  - lib/tdd_deploy/railengine.rb
96
97
  - lib/tdd_deploy/run_methods.rb
97
98
  - lib/tdd_deploy/server.rb