nginx_test_helper 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/nginx_test_helper/rspec_utils.rb +2 -0
- data/lib/nginx_test_helper/version.rb +1 -1
- data/lib/nginx_test_helper.rb +12 -9
- data/spec/nginx_test_helper/command_line_tool_spec.rb +4 -3
- data/spec/nginx_test_helper/config_spec.rb +1 -0
- data/spec/nginx_test_helper/rspec_utils_spec.rb +1 -0
- data/spec/nginx_test_helper_spec.rb +83 -84
- data/spec/spec_helper.rb +0 -3
- metadata +15 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75c520d4f170c613f24605612e69088fedb3a219
|
4
|
+
data.tar.gz: a7c16004fb9a1a01a89ff5d331fef4376978c689
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 706b0d4e95fbfae35443faad3f6916e223e2a8074c2e866fa336689d4c1a7d1231d1d1f3d6662902e8b2d8297c94fc4c2b45f86c57c137ea993ada8f8f89d59f
|
7
|
+
data.tar.gz: 9a843a5c7cb60820a533db67dc3e226d37039d045e19c7ef4ee88bb97b364ee9a15ad2398c632a7ce925832ca30e66774ff8c5d6a36fac0b8d10bb5c07a2c11d
|
data/lib/nginx_test_helper.rb
CHANGED
@@ -45,20 +45,23 @@ module NginxTestHelper
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def read_response_on_socket(socket, wait_for=nil)
|
48
|
+
will_retry = false
|
48
49
|
response ||= socket.readpartial(1)
|
49
50
|
while (tmp = socket.read_nonblock(256))
|
50
51
|
response += tmp
|
51
52
|
end
|
52
53
|
rescue Errno::EAGAIN => e
|
53
|
-
|
54
|
-
|
54
|
+
unless(wait_for.nil? || response.include?(wait_for))
|
55
|
+
will_retry = true
|
55
56
|
IO.select([socket])
|
56
57
|
retry
|
57
58
|
end
|
58
59
|
ensure
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
unless will_retry
|
61
|
+
fail("Any response") if response.nil?
|
62
|
+
headers, body = response.split("\r\n\r\n", 2)
|
63
|
+
return headers, body
|
64
|
+
end
|
62
65
|
end
|
63
66
|
|
64
67
|
def time_diff_milli(start, finish)
|
@@ -76,14 +79,14 @@ module NginxTestHelper
|
|
76
79
|
def start_server(config)
|
77
80
|
error_message = ""
|
78
81
|
unless config.configuration[:disable_start_stop_server]
|
79
|
-
working_dir = nginx_tests_core_dir(config_id)
|
82
|
+
working_dir = nginx_tests_core_dir(config.config_id)
|
80
83
|
FileUtils.mkdir_p working_dir
|
81
84
|
Dir.chdir working_dir do
|
82
85
|
status = POpen4::popen4("#{ config.nginx_executable } -c #{ config.configuration_filename }") do |stdout, stderr, stdin, pid|
|
83
86
|
error_message = stderr.read.strip unless stderr.eof
|
84
87
|
return error_message unless error_message.nil?
|
85
88
|
end
|
86
|
-
fail("Server doesn't started - #{error_message}")
|
89
|
+
fail("Server doesn't started - #{error_message}") if (status.nil? || status.exitstatus != 0)
|
87
90
|
end
|
88
91
|
end
|
89
92
|
error_message
|
@@ -96,7 +99,7 @@ module NginxTestHelper
|
|
96
99
|
error_message = stderr.read.strip unless stderr.eof
|
97
100
|
return error_message unless error_message.nil?
|
98
101
|
end
|
99
|
-
fail("Server doesn't stoped - #{error_message}")
|
102
|
+
fail("Server doesn't stoped - #{error_message}") if (status.nil? || status.exitstatus != 0)
|
100
103
|
end
|
101
104
|
error_message
|
102
105
|
end
|
@@ -115,7 +118,7 @@ private
|
|
115
118
|
end
|
116
119
|
|
117
120
|
def has_passed?
|
118
|
-
if self.respond_to?(:example) && !self.example.nil? && self.example.
|
121
|
+
if self.respond_to?(:example) && !self.example.nil? && self.example.respond_to?(:exception)
|
119
122
|
self.example.exception.nil?
|
120
123
|
elsif !@test_passed.nil?
|
121
124
|
@test_passed
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'nginx_test_helper/command_line_tool'
|
2
3
|
|
3
4
|
describe NginxTestHelper::CommandLineTool do
|
4
5
|
before do
|
5
|
-
$stdout.stub
|
6
|
-
Dir.stub
|
6
|
+
$stdout.stub(:puts)
|
7
|
+
Dir.stub(:pwd).and_return('tmp')
|
7
8
|
FileUtils.mkdir_p('tmp/spec')
|
8
9
|
end
|
9
10
|
|
@@ -34,7 +35,7 @@ describe NginxTestHelper::CommandLineTool do
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should include require call on spec_helper if NgincConfiguration is not defined" do
|
37
|
-
Object.stub
|
38
|
+
Object.stub(:const_defined?).with('NginxConfiguration').and_return(false)
|
38
39
|
File.open('tmp/spec/spec_helper.rb', 'w') { |f| f.write("#spec_helper content") }
|
39
40
|
NginxTestHelper::CommandLineTool.new.process ["init"]
|
40
41
|
File.read('tmp/spec/spec_helper.rb').should eql("#spec_helper content\nrequire File.expand_path('nginx_configuration', File.dirname(__FILE__))")
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'nginx_test_helper'
|
2
3
|
|
3
4
|
describe NginxTestHelper do
|
4
|
-
|
5
|
+
|
6
|
+
subject { Object.new.extend(NginxTestHelper) }
|
5
7
|
|
6
8
|
it "should define a method with basic headers" do
|
7
|
-
headers.should eql({'accept' => 'text/html'})
|
9
|
+
subject.headers.should eql({'accept' => 'text/html'})
|
8
10
|
end
|
9
11
|
|
10
12
|
it "should define a method to calculate the difference in seconds of two dates" do
|
11
|
-
time_diff_sec(Time.now, Time.now + 10).should eql(10)
|
13
|
+
subject.time_diff_sec(Time.now, Time.now + 10).should eql(10)
|
12
14
|
end
|
13
15
|
|
14
16
|
it "should define a method to calculate the difference in milliseconds of two dates" do
|
15
|
-
time_diff_milli(Time.now, Time.now + 10).should eql(10000)
|
17
|
+
subject.time_diff_milli(Time.now, Time.now + 10).should eql(10000)
|
16
18
|
end
|
17
19
|
|
18
20
|
context "when working with sockets" do
|
@@ -21,13 +23,13 @@ describe NginxTestHelper do
|
|
21
23
|
it "should be possible to open a socket to a host and port" do
|
22
24
|
TCPSocket.should_receive(:open).with("xpto.com", 100).and_return(socket)
|
23
25
|
|
24
|
-
open_socket("xpto.com", 100).should eql(socket)
|
26
|
+
subject.open_socket("xpto.com", 100).should eql(socket)
|
25
27
|
end
|
26
28
|
|
27
29
|
it "should be possible to do a GET in an url using the opened socket, and receive header and body response" do
|
28
30
|
socket.should_receive(:print).with("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n")
|
29
31
|
|
30
|
-
headers, body = get_in_socket("/index.html", socket)
|
32
|
+
headers, body = subject.get_in_socket("/index.html", socket)
|
31
33
|
headers.should eql("HTTP 200 OK")
|
32
34
|
body.should eql("BODY")
|
33
35
|
end
|
@@ -35,7 +37,7 @@ describe NginxTestHelper do
|
|
35
37
|
it "should be possible specify the host header value to do a GET" do
|
36
38
|
socket.should_receive(:print).with("GET /index.html HTTP/1.1\r\nHost: some_host_value\r\n\r\n")
|
37
39
|
|
38
|
-
headers, body = get_in_socket("/index.html", socket, {:host_header => "some_host_value"})
|
40
|
+
headers, body = subject.get_in_socket("/index.html", socket, {:host_header => "some_host_value"})
|
39
41
|
headers.should eql("HTTP 200 OK")
|
40
42
|
body.should eql("BODY")
|
41
43
|
end
|
@@ -43,22 +45,22 @@ describe NginxTestHelper do
|
|
43
45
|
it "should be possible use http 1.0 to do a GET" do
|
44
46
|
socket.should_receive(:print).with("GET /index.html HTTP/1.0\r\n\r\n")
|
45
47
|
|
46
|
-
headers, body = get_in_socket("/index.html", socket, {:use_http_1_0 => true})
|
48
|
+
headers, body = subject.get_in_socket("/index.html", socket, {:use_http_1_0 => true})
|
47
49
|
headers.should eql("HTTP 200 OK")
|
48
50
|
body.should eql("BODY")
|
49
51
|
end
|
50
52
|
|
51
53
|
it "should pass 'wait_for' attribute to 'read_response_on_socket' method when doing a GET in a url" do
|
52
54
|
socket.should_receive(:print).with("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n")
|
53
|
-
|
55
|
+
subject.should_receive(:read_response_on_socket).with(socket, "wait for")
|
54
56
|
|
55
|
-
get_in_socket("/index.html", socket, {:wait_for => "wait for"})
|
57
|
+
subject.get_in_socket("/index.html", socket, {:wait_for => "wait for"})
|
56
58
|
end
|
57
59
|
|
58
60
|
it "should be possible to do a POST in an url using the opened socket, and receive header and body response" do
|
59
61
|
socket.should_receive(:print).with("POST /service HTTP/1.1\r\nHost: localhost\r\nContent-Length: 4\r\n\r\nBODY")
|
60
62
|
|
61
|
-
headers, body = post_in_socket("/service", "BODY", socket)
|
63
|
+
headers, body = subject.post_in_socket("/service", "BODY", socket)
|
62
64
|
headers.should eql("HTTP 200 OK")
|
63
65
|
body.should eql("BODY")
|
64
66
|
end
|
@@ -66,7 +68,7 @@ describe NginxTestHelper do
|
|
66
68
|
it "should be possible specify the host header value to do a POST" do
|
67
69
|
socket.should_receive(:print).with("POST /service HTTP/1.1\r\nHost: some_host_value\r\nContent-Length: 4\r\n\r\nBODY")
|
68
70
|
|
69
|
-
headers, body = post_in_socket("/service", "BODY", socket, {:host_header => "some_host_value"})
|
71
|
+
headers, body = subject.post_in_socket("/service", "BODY", socket, {:host_header => "some_host_value"})
|
70
72
|
headers.should eql("HTTP 200 OK")
|
71
73
|
body.should eql("BODY")
|
72
74
|
end
|
@@ -74,20 +76,20 @@ describe NginxTestHelper do
|
|
74
76
|
it "should be possible use http 1.0 to do a POST" do
|
75
77
|
socket.should_receive(:print).with("POST /service HTTP/1.0\r\nContent-Length: 4\r\n\r\nBODY")
|
76
78
|
|
77
|
-
headers, body = post_in_socket("/service", "BODY", socket, {:use_http_1_0 => true})
|
79
|
+
headers, body = subject.post_in_socket("/service", "BODY", socket, {:use_http_1_0 => true})
|
78
80
|
headers.should eql("HTTP 200 OK")
|
79
81
|
body.should eql("BODY")
|
80
82
|
end
|
81
83
|
|
82
84
|
it "should pass 'wait_for' attribute to 'read_response_on_socket' method when doing a POST in a url" do
|
83
85
|
socket.should_receive(:print).with("POST /service HTTP/1.1\r\nHost: localhost\r\nContent-Length: 4\r\n\r\nBODY")
|
84
|
-
|
86
|
+
subject.should_receive(:read_response_on_socket).with(socket, "wait for")
|
85
87
|
|
86
|
-
headers, body = post_in_socket("/service", "BODY", socket, {:wait_for => "wait for"})
|
88
|
+
headers, body = subject.post_in_socket("/service", "BODY", socket, {:wait_for => "wait for"})
|
87
89
|
end
|
88
90
|
|
89
91
|
it "should be possible read a response in a opened socket" do
|
90
|
-
headers, body = read_response_on_socket(socket)
|
92
|
+
headers, body = subject.read_response_on_socket(socket)
|
91
93
|
headers.should eql("HTTP 200 OK")
|
92
94
|
body.should eql("BODY")
|
93
95
|
end
|
@@ -96,15 +98,15 @@ describe NginxTestHelper do
|
|
96
98
|
socket.response1 = "X"
|
97
99
|
socket.response2 = "Y"
|
98
100
|
|
99
|
-
headers, body = read_response_on_socket(socket)
|
101
|
+
headers, body = subject.read_response_on_socket(socket)
|
100
102
|
headers.should eql("HTTP 200 OK")
|
101
103
|
body.should eql("BODYXY")
|
102
104
|
end
|
103
105
|
|
104
106
|
it "should raise error if not receive a response" do
|
105
|
-
socket.stub
|
107
|
+
socket.stub(:readpartial).and_raise(Exception)
|
106
108
|
|
107
|
-
expect { read_response_on_socket(socket) }.to raise_error("Any response")
|
109
|
+
expect { subject.read_response_on_socket(socket) }.to raise_error("Any response")
|
108
110
|
end
|
109
111
|
|
110
112
|
context "and receive a Errno::EAGAIN" do
|
@@ -114,7 +116,7 @@ describe NginxTestHelper do
|
|
114
116
|
socket.response3 = "Z"
|
115
117
|
socket.exception = Errno::EAGAIN
|
116
118
|
|
117
|
-
headers, body = read_response_on_socket(socket)
|
119
|
+
headers, body = subject.read_response_on_socket(socket)
|
118
120
|
headers.should eql("HTTP 200 OK")
|
119
121
|
body.should eql("BODYX")
|
120
122
|
end
|
@@ -124,7 +126,7 @@ describe NginxTestHelper do
|
|
124
126
|
it "should check if a text is present in the response" do
|
125
127
|
socket.exception = Errno::EAGAIN
|
126
128
|
|
127
|
-
headers, body = read_response_on_socket(socket, "OD")
|
129
|
+
headers, body = subject.read_response_on_socket(socket, "OD")
|
128
130
|
headers.should eql("HTTP 200 OK")
|
129
131
|
body.should eql("BODY")
|
130
132
|
end
|
@@ -133,9 +135,9 @@ describe NginxTestHelper do
|
|
133
135
|
socket.exception = Errno::EAGAIN
|
134
136
|
socket.response3 = "Z"
|
135
137
|
|
136
|
-
IO.should_receive(:select).with([socket])
|
138
|
+
IO.should_receive(:select).with([socket])
|
137
139
|
|
138
|
-
headers, body = read_response_on_socket(socket, "Z")
|
140
|
+
headers, body = subject.read_response_on_socket(socket, "Z")
|
139
141
|
headers.should eql("HTTP 200 OK")
|
140
142
|
body.should include("BODY")
|
141
143
|
end
|
@@ -145,153 +147,150 @@ describe NginxTestHelper do
|
|
145
147
|
|
146
148
|
context "when testing configuration" do
|
147
149
|
before do
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
subject.stub(:config_id).and_return("config_id")
|
151
|
+
subject.stub(:start_server).and_return("Server started")
|
152
|
+
subject.stub(:stop_server).and_return("Server stoped")
|
151
153
|
end
|
152
154
|
|
153
155
|
it "should create an instance of NginxTestHelper::Config with the given configuation" do
|
154
156
|
config = NginxTestHelper::Config.new("config_id", {:foo => "bar"})
|
155
157
|
NginxTestHelper::Config.should_receive(:new).with("config_id", {:foo => "bar"}).and_return(config)
|
156
|
-
nginx_test_configuration({:foo => "bar"})
|
158
|
+
subject.nginx_test_configuration({:foo => "bar"})
|
157
159
|
end
|
158
160
|
|
159
161
|
it "should accept test default configuration" do
|
160
162
|
config = NginxTestHelper::Config.new("config_id", {})
|
161
163
|
NginxTestHelper::Config.should_receive(:new).with("config_id", {}).and_return(config)
|
162
|
-
nginx_test_configuration
|
164
|
+
subject.nginx_test_configuration
|
163
165
|
end
|
164
166
|
|
165
167
|
it "should call start_server and stop_server methods" do
|
166
|
-
|
167
|
-
|
168
|
-
nginx_test_configuration({:foo => "bar"})
|
168
|
+
subject.should_receive(:start_server).and_return("Server started")
|
169
|
+
subject.should_receive(:stop_server).and_return("Server stoped")
|
170
|
+
subject.nginx_test_configuration({:foo => "bar"})
|
169
171
|
end
|
170
172
|
|
171
173
|
it "should return start command result" do
|
172
|
-
nginx_test_configuration({:foo => "bar"}).should eql("Server started\n")
|
174
|
+
subject.nginx_test_configuration({:foo => "bar"}).should eql("Server started\n")
|
173
175
|
end
|
174
176
|
|
175
177
|
it "should return start command result concatenated with error log content if exists" do
|
176
178
|
FileUtils.mkdir_p("/tmp/nginx_tests/logs/")
|
177
179
|
File.open("/tmp/nginx_tests/logs/error-config_id.log", "w") { |f| f.write("Error log content") }
|
178
|
-
nginx_test_configuration({:foo => "bar"}).should eql("Server started\nError log content")
|
180
|
+
subject.nginx_test_configuration({:foo => "bar"}).should eql("Server started\nError log content")
|
179
181
|
end
|
180
182
|
end
|
181
183
|
|
182
184
|
context "when starting server to make tests" do
|
183
185
|
before do
|
184
|
-
|
185
|
-
|
186
|
-
|
186
|
+
subject.stub(:config_id).and_return("config_id")
|
187
|
+
subject.stub(:start_server).and_return("Server started")
|
188
|
+
subject.stub(:stop_server).and_return("Server stoped")
|
187
189
|
end
|
188
190
|
|
189
191
|
it "should create an instance of NginxTestHelper::Config with the given configuation" do
|
190
192
|
config = NginxTestHelper::Config.new("config_id", {:foo => "bar"})
|
191
193
|
NginxTestHelper::Config.should_receive(:new).with("config_id", {:foo => "bar"}).and_return(config)
|
192
|
-
nginx_run_server({:foo => "bar"}) {}
|
194
|
+
subject.nginx_run_server({:foo => "bar"}) {}
|
193
195
|
end
|
194
196
|
|
195
197
|
it "should accept test default configuration" do
|
196
198
|
config = NginxTestHelper::Config.new("config_id", {})
|
197
199
|
NginxTestHelper::Config.should_receive(:new).with("config_id", {}).and_return(config)
|
198
|
-
nginx_run_server {}
|
200
|
+
subject.nginx_run_server {}
|
199
201
|
end
|
200
202
|
|
201
203
|
it "should execute the block after start_server and before stop_server methods" do
|
202
204
|
obj = {:xyz => 1}
|
203
|
-
|
205
|
+
subject.should_receive(:start_server).ordered
|
204
206
|
obj.should_receive(:delete).with(:xyz).ordered
|
205
|
-
|
207
|
+
subject.should_receive(:stop_server).ordered
|
206
208
|
|
207
|
-
nginx_run_server({:foo => "bar"}) { obj.delete(:xyz) }
|
209
|
+
subject.nginx_run_server({:foo => "bar"}) { obj.delete(:xyz) }
|
208
210
|
end
|
209
211
|
|
210
212
|
it "should execute the block inside a timeout block" do
|
211
|
-
expect { nginx_run_server({:foo => "bar"}) { sleep 6 } }.to raise_error(Timeout::Error, "execution expired")
|
213
|
+
expect { subject.nginx_run_server({:foo => "bar"}) { sleep 6 } }.to raise_error(Timeout::Error, "execution expired")
|
212
214
|
end
|
213
215
|
|
214
216
|
it "should accept a custom a timeout" do
|
215
|
-
expect { nginx_run_server({:foo => "bar"}, {:timeout => 2}) { sleep 6 } }.to raise_error(Timeout::Error, "execution expired")
|
216
|
-
expect { nginx_run_server({:foo => "bar"}, {:timeout => 2}) { sleep 1 } }.to_not raise_error
|
217
|
+
expect { subject.nginx_run_server({:foo => "bar"}, {:timeout => 2}) { sleep 6 } }.to raise_error(Timeout::Error, "execution expired")
|
218
|
+
expect { subject.nginx_run_server({:foo => "bar"}, {:timeout => 2}) { sleep 1 } }.to_not raise_error
|
217
219
|
end
|
218
220
|
|
219
221
|
it "should execute stop_server method if an exception was raised" do
|
220
|
-
|
221
|
-
expect { nginx_run_server({:foo => "bar"}) { raise "some error" } }.to raise_error("some error")
|
222
|
+
subject.should_receive(:stop_server)
|
223
|
+
expect { subject.nginx_run_server({:foo => "bar"}) { raise "some error" } }.to raise_error("some error")
|
222
224
|
end
|
223
225
|
end
|
224
226
|
|
225
227
|
context "when checking internal behavior" do
|
226
228
|
before do
|
227
|
-
|
228
|
-
|
229
|
+
subject.stub(:start_server).and_return("Server started")
|
230
|
+
subject.stub(:stop_server).and_return("Server stoped")
|
231
|
+
subject.stub(:example).and_return(double)
|
229
232
|
end
|
230
233
|
|
231
234
|
context "and check config_id value" do
|
232
235
|
it "should use example metadata if available" do
|
233
|
-
|
234
|
-
|
236
|
+
subject.example.stub(:metadata).and_return(:location => "./spec/test_config_id_spec.rb:100")
|
237
|
+
subject.send(:config_id).should eql("test_config_id_spec_rb_100")
|
235
238
|
end
|
236
239
|
|
237
240
|
it "should use method_name if example metadata is not available" do
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
self.send(:config_id).should eql("test_config_id_by_method_name")
|
241
|
+
subject.example.stub(:metadata).and_return(nil)
|
242
|
+
subject.stub(:method_name).and_return("test_config_id_by_method_name")
|
243
|
+
|
244
|
+
subject.send(:config_id).should eql("test_config_id_by_method_name")
|
243
245
|
end
|
244
246
|
|
245
247
|
it "should use __name__ if example metadata and method_name are not available" do
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
self.send(:config_id).should eql("test_config_id_by___name__")
|
248
|
+
subject.example.stub(:metadata).and_return(nil)
|
249
|
+
subject.stub(:__name__).and_return("test_config_id_by___name__")
|
250
|
+
|
251
|
+
subject.send(:config_id).should eql("test_config_id_by___name__")
|
251
252
|
end
|
252
253
|
end
|
253
254
|
|
254
255
|
context "and check if the test has passed" do
|
255
256
|
context "using example exception if available" do
|
256
257
|
it "should be 'true' if exception is 'nil'" do
|
257
|
-
|
258
|
-
|
258
|
+
subject.example.stub(:exception).and_return(nil)
|
259
|
+
subject.send(:has_passed?).should be_true
|
259
260
|
end
|
260
261
|
|
261
262
|
it "should be 'false' if exception is not 'nil'" do
|
262
|
-
|
263
|
-
|
263
|
+
subject.example.stub(:exception).and_return("")
|
264
|
+
subject.send(:has_passed?).should be_false
|
264
265
|
end
|
265
266
|
end
|
266
267
|
|
267
268
|
context "using 'test_passed' attribute if example exception is not available" do
|
268
|
-
before { self.example.stub!(:instance_variable_defined?).with(:@exception).and_return(false) }
|
269
|
-
|
270
269
|
it "should be 'true' if 'test_passed' is 'true'" do
|
271
|
-
|
272
|
-
|
270
|
+
subject.instance_variable_set(:@test_passed, true)
|
271
|
+
subject.send(:has_passed?).should be_true
|
273
272
|
end
|
274
273
|
|
275
274
|
it "should be 'false' if 'test_passed' is 'false'" do
|
276
|
-
|
277
|
-
|
275
|
+
subject.instance_variable_set(:@test_passed, false)
|
276
|
+
subject.send(:has_passed?).should be_false
|
278
277
|
end
|
279
278
|
end
|
280
279
|
|
281
280
|
context "using 'passed' attribute if example exception and 'test_passed' are not available" do
|
282
281
|
before do
|
283
|
-
|
284
|
-
|
282
|
+
subject.example.stub(:instance_variable_defined?).with(:@exception).and_return(false)
|
283
|
+
subject.instance_variable_set(:@test_passed, nil)
|
285
284
|
end
|
286
285
|
|
287
286
|
it "should be 'true' if 'passed' is 'true'" do
|
288
|
-
|
289
|
-
|
287
|
+
subject.instance_variable_set(:@passed, true)
|
288
|
+
subject.send(:has_passed?).should be_true
|
290
289
|
end
|
291
290
|
|
292
291
|
it "should be 'false' if 'passed' is 'false'" do
|
293
|
-
|
294
|
-
|
292
|
+
subject.instance_variable_set(:@passed, false)
|
293
|
+
subject.send(:has_passed?).should be_false
|
295
294
|
end
|
296
295
|
end
|
297
296
|
end
|
@@ -303,23 +302,23 @@ describe NginxTestHelper do
|
|
303
302
|
|
304
303
|
it "should use POpen4 to execute the command" do
|
305
304
|
POpen4.should_receive(:popen4).with("/usr/local/nginx/sbin/nginx -c /tmp/nginx_tests/config_id.conf").and_return(status)
|
306
|
-
start_server(config)
|
305
|
+
subject.start_server(config)
|
307
306
|
end
|
308
307
|
|
309
308
|
it "should not start the server if configuration has a key 'disable_start_stop_server' with 'true'" do
|
310
309
|
config.configuration[:disable_start_stop_server] = true
|
311
310
|
POpen4.should_not_receive(:popen4)
|
312
|
-
start_server(config)
|
311
|
+
subject.start_server(config)
|
313
312
|
end
|
314
313
|
|
315
314
|
it "should raise error if 'exitstatus' is not '0'" do
|
316
315
|
status.exitstatus = 1
|
317
316
|
POpen4.should_receive(:popen4).with("/usr/local/nginx/sbin/nginx -c /tmp/nginx_tests/config_id.conf").and_return(status)
|
318
|
-
expect { start_server(config) }.to raise_error("Server doesn't started - ")
|
317
|
+
expect { subject.start_server(config) }.to raise_error("Server doesn't started - ")
|
319
318
|
end
|
320
319
|
|
321
320
|
it "should return error message when the command fail" do
|
322
|
-
start_server(config).should eql("nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /tmp/nginx_tests/config_id.conf:1")
|
321
|
+
subject.start_server(config).should eql("nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /tmp/nginx_tests/config_id.conf:1")
|
323
322
|
end
|
324
323
|
end
|
325
324
|
|
@@ -329,23 +328,23 @@ describe NginxTestHelper do
|
|
329
328
|
|
330
329
|
it "should use POpen4 to execute the command" do
|
331
330
|
POpen4.should_receive(:popen4).with("/usr/local/nginx/sbin/nginx -c /tmp/nginx_tests/config_id.conf -s stop").and_return(status)
|
332
|
-
stop_server(config)
|
331
|
+
subject.stop_server(config)
|
333
332
|
end
|
334
333
|
|
335
334
|
it "should not start the server if configuration has a key 'disable_start_stop_server' with 'true'" do
|
336
335
|
config.configuration[:disable_start_stop_server] = true
|
337
336
|
POpen4.should_not_receive(:popen4)
|
338
|
-
stop_server(config)
|
337
|
+
subject.stop_server(config)
|
339
338
|
end
|
340
339
|
|
341
340
|
it "should raise error if 'exitstatus' is not '0'" do
|
342
341
|
status.exitstatus = 1
|
343
342
|
POpen4.should_receive(:popen4).with("/usr/local/nginx/sbin/nginx -c /tmp/nginx_tests/config_id.conf -s stop").and_return(status)
|
344
|
-
expect { stop_server(config) }.to raise_error("Server doesn't stoped - ")
|
343
|
+
expect { subject.stop_server(config) }.to raise_error("Server doesn't stoped - ")
|
345
344
|
end
|
346
345
|
|
347
346
|
it "should return error message when the command fail" do
|
348
|
-
stop_server(config).should eql("nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /tmp/nginx_tests/config_id.conf:1")
|
347
|
+
subject.stop_server(config).should eql("nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /tmp/nginx_tests/config_id.conf:1")
|
349
348
|
end
|
350
349
|
end
|
351
350
|
|
data/spec/spec_helper.rb
CHANGED
@@ -27,9 +27,6 @@ rescue LoadError
|
|
27
27
|
# ignore simplecov in ruby < 1.9
|
28
28
|
end
|
29
29
|
|
30
|
-
# Requires lib.
|
31
|
-
Dir[File.expand_path('../lib/**/*.rb', File.dirname(__FILE__))].each { |f| require f }
|
32
|
-
|
33
30
|
def with_constants(constants, &block)
|
34
31
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
35
32
|
saved_constants = {}
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginx_test_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Wandenberg Peixoto
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: popen4
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 2.10.0
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 2.10.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: debugger
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 1.1.3
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 1.1.3
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: simplecov
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 0.0.1
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 0.0.1
|
78
69
|
description: A collection of helper methods to test your nginx module.
|
@@ -110,27 +101,26 @@ files:
|
|
110
101
|
- templates/spec/nginx_configuration.rb
|
111
102
|
homepage: ''
|
112
103
|
licenses: []
|
104
|
+
metadata: {}
|
113
105
|
post_install_message:
|
114
106
|
rdoc_options: []
|
115
107
|
require_paths:
|
116
108
|
- lib
|
117
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
110
|
requirements:
|
120
|
-
- -
|
111
|
+
- - '>='
|
121
112
|
- !ruby/object:Gem::Version
|
122
113
|
version: '0'
|
123
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
115
|
requirements:
|
126
|
-
- -
|
116
|
+
- - '>='
|
127
117
|
- !ruby/object:Gem::Version
|
128
118
|
version: '0'
|
129
119
|
requirements: []
|
130
120
|
rubyforge_project:
|
131
|
-
rubygems_version:
|
121
|
+
rubygems_version: 2.2.2
|
132
122
|
signing_key:
|
133
|
-
specification_version:
|
123
|
+
specification_version: 4
|
134
124
|
summary: A collection of helper methods to test your nginx module.
|
135
125
|
test_files:
|
136
126
|
- spec/nginx_test_helper/command_line_tool_spec.rb
|