resty_test 0.1.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.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +29 -0
- data/Rakefile +9 -0
- data/lib/resty_test/config.rb +41 -0
- data/lib/resty_test/installer.rb +58 -0
- data/lib/resty_test/paths.rb +20 -0
- data/lib/resty_test.rb +54 -0
- data/resty_test.gemspec +24 -0
- data/spec/nginx.conf +14 -0
- data/spec/resty_test/config_spec.rb +19 -0
- data/spec/resty_test/installer_spec.rb +20 -0
- data/spec/resty_test_spec.rb +30 -0
- data/spec/spec_helper.rb +8 -0
- metadata +128 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
spec/resty/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
resty_test (0.1.0)
|
5
|
+
excon
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
excon (0.16.10)
|
12
|
+
rake (10.0.3)
|
13
|
+
rspec (2.12.0)
|
14
|
+
rspec-core (~> 2.12.0)
|
15
|
+
rspec-expectations (~> 2.12.0)
|
16
|
+
rspec-mocks (~> 2.12.0)
|
17
|
+
rspec-core (2.12.2)
|
18
|
+
rspec-expectations (2.12.1)
|
19
|
+
diff-lcs (~> 1.1.3)
|
20
|
+
rspec-mocks (2.12.1)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler
|
27
|
+
rake
|
28
|
+
resty_test!
|
29
|
+
rspec
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class RestyTest::Config
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
attr_writer :source, :logger, :build_opts, :config_file
|
5
|
+
attr_accessor :root
|
6
|
+
|
7
|
+
def source
|
8
|
+
@source ||= "http://agentzh.org/misc/nginx/ngx_openresty-1.2.4.14.tar.gz"
|
9
|
+
end
|
10
|
+
|
11
|
+
def logger
|
12
|
+
@logger ||= Logger.new(STDOUT).tap do |l|
|
13
|
+
l.level = Logger::INFO
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def config_file
|
18
|
+
@config_file ||= File.expand_path("../nginx.conf", RestyTest.paths.root)
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_opts
|
22
|
+
@build_opts ||= ["--with-luajit", *platform_specific_build_options]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def platform_specific_build_options
|
28
|
+
case RUBY_PLATFORM
|
29
|
+
when /darwin/i
|
30
|
+
pcre = Dir["/usr/local/Cellar/pcre/*/include", "/usr/local/pcre/*/include"].sort[-1]
|
31
|
+
if pcre
|
32
|
+
["--with-cc-opt='-I#{pcre}'", "--with-ld-opt='-L#{File.dirname(pcre)}/lib'"]
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
else
|
37
|
+
[]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class RestyTest::Installer
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
def download!
|
5
|
+
return if File.file?(paths.tar)
|
6
|
+
|
7
|
+
log "Downloading #{File.basename(paths.tar)}", :info
|
8
|
+
FileUtils.mkdir_p(paths.root)
|
9
|
+
File.open(paths.tar, "wb") do |file|
|
10
|
+
Excon.get RestyTest.config.source, response_block: lambda {|c, _, _| file.write(c) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def extract!
|
15
|
+
download!
|
16
|
+
return if File.file?(File.join(paths.src, "configure"))
|
17
|
+
|
18
|
+
log "Extracting source", :info
|
19
|
+
sh "cd #{paths.root} && mkdir -p src && /usr/bin/env tar xzf #{paths.tar} -C src --strip-components 1"
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure!
|
23
|
+
extract!
|
24
|
+
return if File.file?(File.join(paths.src, "Makefile"))
|
25
|
+
|
26
|
+
log "Configuring", :info
|
27
|
+
sh "cd #{paths.src} && ./configure --prefix='#{paths.root}' #{opts}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def install!
|
31
|
+
configure!
|
32
|
+
return if File.file?(paths.nginx_bin)
|
33
|
+
|
34
|
+
log "Building & installing", :info
|
35
|
+
sh "cd #{paths.src} && make && make install"
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def sh(cmd)
|
41
|
+
log cmd
|
42
|
+
log `#{cmd}`
|
43
|
+
raise "Abort!" unless $? == 0
|
44
|
+
end
|
45
|
+
|
46
|
+
def paths
|
47
|
+
RestyTest.paths
|
48
|
+
end
|
49
|
+
|
50
|
+
def opts
|
51
|
+
RestyTest.config.build_opts.join(" ")
|
52
|
+
end
|
53
|
+
|
54
|
+
def log(message, level = :debug)
|
55
|
+
RestyTest.logger.send(level, message)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class RestyTest::Paths
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
def root
|
5
|
+
RestyTest.config.root
|
6
|
+
end
|
7
|
+
|
8
|
+
def tar
|
9
|
+
File.join(root, File.basename(RestyTest.config.source))
|
10
|
+
end
|
11
|
+
|
12
|
+
def src
|
13
|
+
File.join(root, "src")
|
14
|
+
end
|
15
|
+
|
16
|
+
def nginx_bin
|
17
|
+
File.join(root, "nginx", "sbin", "nginx")
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/resty_test.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'excon'
|
3
|
+
require 'singleton'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module RestyTest
|
7
|
+
require 'resty_test/config'
|
8
|
+
require 'resty_test/paths'
|
9
|
+
require 'resty_test/installer'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_reader :running
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield config
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
self::Config.instance
|
20
|
+
end
|
21
|
+
|
22
|
+
def installer
|
23
|
+
self::Installer.instance
|
24
|
+
end
|
25
|
+
|
26
|
+
def paths
|
27
|
+
RestyTest::Paths.instance
|
28
|
+
end
|
29
|
+
|
30
|
+
def logger
|
31
|
+
config.logger
|
32
|
+
end
|
33
|
+
|
34
|
+
def start!
|
35
|
+
installer.install!
|
36
|
+
system "#{paths.nginx_bin} -c #{config.config_file}"
|
37
|
+
@running = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def stop!
|
41
|
+
return unless File.file?(paths.nginx_bin) && running
|
42
|
+
system "#{paths.nginx_bin} -s stop"
|
43
|
+
@running = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
root = caller.detect {|path| path =~ /^(.+?\/(?:test|spec|features))\// }
|
49
|
+
config.root = "#{$1}/resty" if root
|
50
|
+
|
51
|
+
at_exit do
|
52
|
+
stop!
|
53
|
+
end
|
54
|
+
end
|
data/resty_test.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.required_ruby_version = '>= 1.9.1'
|
5
|
+
s.required_rubygems_version = ">= 1.8.0"
|
6
|
+
|
7
|
+
s.name = File.basename(__FILE__, '.gemspec')
|
8
|
+
s.summary = "RestyTest"
|
9
|
+
s.description = "Test OpenResty with your favourite test framework!"
|
10
|
+
s.version = "0.1.0"
|
11
|
+
|
12
|
+
s.authors = ["Dimitrij Denissenko"]
|
13
|
+
s.email = "dimitrij@blacksquaremedia.com"
|
14
|
+
s.homepage = "https://github.com/bsm/resty_test"
|
15
|
+
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
|
+
|
20
|
+
s.add_dependency "excon"
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "bundler"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
end
|
data/spec/nginx.conf
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestyTest::Config do
|
4
|
+
|
5
|
+
subject { described_class.instance }
|
6
|
+
it { should be_a(Singleton) }
|
7
|
+
|
8
|
+
its(:root) { should be_instance_of(String) }
|
9
|
+
its(:logger) { should be_instance_of(Logger) }
|
10
|
+
its(:source) { should be_instance_of(String) }
|
11
|
+
its(:config_file) { should == File.expand_path("../../nginx.conf", __FILE__) }
|
12
|
+
its(:build_opts) { should be_instance_of(Array) }
|
13
|
+
|
14
|
+
[:root, :source, :logger, :build_opts, :config_file].each do |name|
|
15
|
+
it { should respond_to(name) }
|
16
|
+
it { should respond_to(:"#{name}=") }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestyTest::Installer do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@level = RestyTest.logger.level
|
7
|
+
RestyTest.logger.level = Logger::WARN
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
RestyTest.logger.level = @level
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { described_class.instance }
|
15
|
+
it { should be_a(Singleton) }
|
16
|
+
|
17
|
+
its(:opts) { should be_instance_of(String) }
|
18
|
+
its(:paths) { should be_instance_of(RestyTest::Paths) }
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestyTest do
|
4
|
+
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
its(:config) { should be_instance_of(described_class::Config) }
|
8
|
+
its(:logger) { should be_instance_of(Logger) }
|
9
|
+
|
10
|
+
it "should be configurable" do
|
11
|
+
subject.configure do |c|
|
12
|
+
c.root.should == File.expand_path("../resty", __FILE__)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should start and stop nginx" do
|
17
|
+
lambda { subject.start! }.should change {
|
18
|
+
subject.running
|
19
|
+
}.from(nil).to(true)
|
20
|
+
|
21
|
+
res = Excon.get("http://127.0.0.1:1984/")
|
22
|
+
res.status.should == 200
|
23
|
+
res.body.should == "Success!\n"
|
24
|
+
|
25
|
+
lambda { subject.stop! }.should change {
|
26
|
+
subject.running
|
27
|
+
}.from(true).to(nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resty_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimitrij Denissenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: excon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Test OpenResty with your favourite test framework!
|
79
|
+
email: dimitrij@blacksquaremedia.com
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- .gitignore
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- Rakefile
|
88
|
+
- lib/resty_test.rb
|
89
|
+
- lib/resty_test/config.rb
|
90
|
+
- lib/resty_test/installer.rb
|
91
|
+
- lib/resty_test/paths.rb
|
92
|
+
- resty_test.gemspec
|
93
|
+
- spec/nginx.conf
|
94
|
+
- spec/resty_test/config_spec.rb
|
95
|
+
- spec/resty_test/installer_spec.rb
|
96
|
+
- spec/resty_test_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: https://github.com/bsm/resty_test
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.9.1
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 1.8.0
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: RestyTest
|
122
|
+
test_files:
|
123
|
+
- spec/nginx.conf
|
124
|
+
- spec/resty_test/config_spec.rb
|
125
|
+
- spec/resty_test/installer_spec.rb
|
126
|
+
- spec/resty_test_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
has_rdoc:
|