rest-assured 0.2.0.rc7 → 0.2.0.rc8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -6
- data/bin/rest-assured +31 -12
- data/features/call_history.feature +0 -1
- data/features/command_line_options.feature +55 -0
- data/features/step_definitions/command_line_options_steps.rb +35 -0
- data/features/step_definitions/doubles_steps.rb +4 -0
- data/features/support/env.rb +3 -2
- data/features/support/world_helpers.rb +31 -0
- data/lib/rest-assured.rb +3 -20
- data/lib/rest-assured/config.rb +138 -13
- data/lib/rest-assured/version.rb +1 -1
- data/{views/base.scss → public/css/base.css} +0 -0
- data/rest-assured.gemspec +0 -1
- data/spec/config_spec.rb +98 -0
- data/spec/spec_helper.rb +1 -1
- metadata +17 -28
- data/features/step_definitions/persistence_steps.rb +0 -13
- data/lib/rest-assured/init.rb +0 -78
data/Gemfile.lock
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest-assured (0.2.0.
|
4
|
+
rest-assured (0.2.0.rc7)
|
5
5
|
activerecord (~> 3.1.0)
|
6
6
|
activeresource (~> 3.1.0)
|
7
7
|
haml (>= 3.1.3)
|
8
8
|
rack-flash (>= 0.1.2)
|
9
|
-
sass (>= 3.1.8)
|
10
9
|
sinatra (>= 1.3.1)
|
11
10
|
|
12
11
|
GEM
|
@@ -96,7 +95,6 @@ GEM
|
|
96
95
|
ruby-debug-base (0.10.4)
|
97
96
|
linecache (>= 0.3)
|
98
97
|
rubyzip (0.9.4)
|
99
|
-
sass (3.1.10)
|
100
98
|
selenium-webdriver (2.9.1)
|
101
99
|
childprocess (>= 0.2.1)
|
102
100
|
ffi (= 1.0.9)
|
@@ -104,9 +102,9 @@ GEM
|
|
104
102
|
rubyzip
|
105
103
|
shoulda-matchers (1.0.0.beta3)
|
106
104
|
sinatra (1.3.1)
|
107
|
-
rack (
|
108
|
-
rack-protection (
|
109
|
-
tilt (
|
105
|
+
rack (~> 1.3, >= 1.3.4)
|
106
|
+
rack-protection (~> 1.1, >= 1.1.2)
|
107
|
+
tilt (~> 1.3, >= 1.3.3)
|
110
108
|
sinatra-activerecord (0.1.3)
|
111
109
|
sinatra (>= 0.9.4)
|
112
110
|
spoon (0.0.1)
|
data/bin/rest-assured
CHANGED
@@ -6,39 +6,58 @@ require 'rubygems'
|
|
6
6
|
require 'optparse'
|
7
7
|
require 'rest-assured/config'
|
8
8
|
|
9
|
+
user_opts = {}
|
10
|
+
|
9
11
|
OptionParser.new do |opts|
|
10
12
|
opts.banner = "Usage: rest-assured [options]"
|
11
13
|
|
12
14
|
opts.on('-a', '--adapter mysql|sqlite') do |adapter|
|
13
|
-
|
15
|
+
user_opts[:adapter] = adapter
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-d', '--database FILENAME', "Either path to database file (sqlite, defaults to ./rest-assured.db) or db name (defaults to rest_assured)") do |fname|
|
19
|
+
user_opts[:database] = fname
|
14
20
|
end
|
15
21
|
|
16
|
-
opts.on('-
|
17
|
-
|
22
|
+
opts.on('-u', '--dbuser DBUSER', "Db username (mysql only)") do |user|
|
23
|
+
user_opts[:user] = user
|
18
24
|
end
|
19
25
|
|
20
|
-
opts.on('--
|
21
|
-
|
26
|
+
opts.on('--dbpass DBPASSWORD', 'Db password (mysql only). Defaults to empty') do |password|
|
27
|
+
user_opts[:dbpass] = password
|
22
28
|
end
|
23
29
|
|
24
|
-
opts.on('--
|
25
|
-
|
30
|
+
opts.on('--dbhost DBHOST', 'Db host (mysql only). Defaults to mysql default host (localhost)') do |dbhost|
|
31
|
+
user_opts[:dbhost] = dbhost
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('--dbport DBPORT', Integer, 'Db port (mysql only). Defaults to mysql default port (3306)') do |dbport|
|
35
|
+
user_opts[:dbport] = dbport
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('--dbencoding DBENCODING', 'Db encoding (mysql only). Defaults to mysql default encoding') do |dbencoding|
|
39
|
+
user_opts[:dbencoding] = dbencoding
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('--dbsocket DBSOCKET', 'Db socket (mysql only). Defaults to mysql default socket') do |dbsocket|
|
43
|
+
user_opts[:dbsocket] = dbsocket
|
26
44
|
end
|
27
45
|
|
28
46
|
opts.on('-p', '--port PORT', Integer, "Server port. Defaults to 4578") do |port|
|
29
|
-
|
47
|
+
user_opts[:port] = port
|
30
48
|
end
|
31
49
|
|
32
|
-
opts.on('-l', '--logfile FILENAME', "Path to logfile. Defaults to ./rest-assured.log") do |
|
33
|
-
|
50
|
+
opts.on('-l', '--logfile FILENAME', "Path to logfile. Defaults to ./rest-assured.log") do |logfile|
|
51
|
+
user_opts[:logfile] = logfile
|
34
52
|
end
|
35
53
|
|
36
|
-
opts.on_tail("
|
54
|
+
opts.on_tail("--help", "Show this message") do
|
37
55
|
puts opts
|
38
56
|
exit
|
39
57
|
end
|
40
58
|
end.parse!
|
41
59
|
|
42
|
-
|
60
|
+
RestAssured::Config.build(user_opts)
|
43
61
|
|
62
|
+
require 'rest-assured'
|
44
63
|
RestAssured::Application.run!
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Feature: command line options
|
2
|
+
In order to run rest-assured in different configurations (db params, port, etc)
|
3
|
+
As test developer
|
4
|
+
I need a way to specify those configurations.
|
5
|
+
|
6
|
+
Scenario Outline: specifying server port
|
7
|
+
When I start rest-assured with <option>
|
8
|
+
Then it should run on port <port>
|
9
|
+
|
10
|
+
Examples:
|
11
|
+
| option | port |
|
12
|
+
| -p 1234 | 1234 |
|
13
|
+
| --port 1235 | 1235 |
|
14
|
+
| | 4578 |
|
15
|
+
|
16
|
+
Scenario Outline: specifying log file
|
17
|
+
When I start rest-assured with <option>
|
18
|
+
Then the log file should be <logfile>
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
| option | logfile |
|
22
|
+
| -l /tmp/rest-assured.log | /tmp/rest-assured.log |
|
23
|
+
| --logfile ./test.log | ./test.log |
|
24
|
+
| | ./rest-assured.log |
|
25
|
+
|
26
|
+
Scenario Outline: sqlite options
|
27
|
+
When I start rest-assured with <options>
|
28
|
+
Then database adapter should be sqlite and db file should be <dbfile>
|
29
|
+
|
30
|
+
Examples:
|
31
|
+
| options | dbfile |
|
32
|
+
| | ./rest-assured.db |
|
33
|
+
| -d /tmp/ratest.db | /tmp/ratest.db |
|
34
|
+
| --database /tmp/resta.db | /tmp/resta.db |
|
35
|
+
|
36
|
+
@now
|
37
|
+
Scenario Outline: mysql options
|
38
|
+
When I start rest-assured with -a mysql <options>
|
39
|
+
Then database options should be:
|
40
|
+
| dbname | dbuser | dbpass | dbhost | dbport | dbencoding | dbsocket |
|
41
|
+
| <dbname> | <dbuser> | <dbpass> | <dbhost> | <dbport> | <dbencoding> | <dbsocket> |
|
42
|
+
|
43
|
+
Examples:
|
44
|
+
| options | dbname | dbuser | dbpass | dbhost | dbport | dbencoding | dbsocket |
|
45
|
+
| | rest_assured | root | | | | | |
|
46
|
+
| -d resta | resta | root | | | | | |
|
47
|
+
| --database resta | resta | root | | | | | |
|
48
|
+
| -u bob | rest_assured | bob | | | | | |
|
49
|
+
| --dbuser bob | rest_assured | bob | | | | | |
|
50
|
+
| --dbpass pswd | rest_assured | root | pswd | | | | |
|
51
|
+
| --dbhost remote | rest_assured | root | | remote | | | |
|
52
|
+
| --dbport 5555 | rest_assured | root | | | 5555 | | |
|
53
|
+
| --dbencoding utf16le | rest_assured | root | | | | utf16le | |
|
54
|
+
| --dbsocket /tmp/mysql.sock | rest_assured | root | | | | | /tmp/mysql.sock |
|
55
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
When /^I start rest\-assured with (.*)$/ do |options|
|
2
|
+
@app_config = fake_start_rest_assured(options)
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^it should run on port (\d+)$/ do |port|
|
6
|
+
@app_config[:port].should == port
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^the log file should be (.*)$/ do |logfile|
|
10
|
+
@app_config[:logfile].should == logfile
|
11
|
+
`rm #{logfile}`
|
12
|
+
end
|
13
|
+
|
14
|
+
Then /^database adapter should be sqlite and db file should be (.*)$/ do |dbfile|
|
15
|
+
@app_config[:db_config][:database].should == dbfile
|
16
|
+
@app_config[:db_config][:adapter].should == 'sqlite3'
|
17
|
+
`rm #{dbfile}`
|
18
|
+
end
|
19
|
+
|
20
|
+
Then /^database options should be:$/ do |table|
|
21
|
+
res = table.hashes.first
|
22
|
+
|
23
|
+
empty_to_nil = lambda do |string|
|
24
|
+
string.empty? ? nil : string
|
25
|
+
end
|
26
|
+
|
27
|
+
@app_config[:db_config][:adapter].should == 'mysql'
|
28
|
+
@app_config[:db_config][:database].should == res['dbname']
|
29
|
+
@app_config[:db_config][:user].should == res['dbuser']
|
30
|
+
@app_config[:db_config][:password].should == empty_to_nil[res['dbpass']]
|
31
|
+
@app_config[:db_config][:host].should == empty_to_nil[res['dbhost']]
|
32
|
+
@app_config[:db_config][:port].should == empty_to_nil[res['dbport']].try(:to_i)
|
33
|
+
@app_config[:db_config][:encoding].should == empty_to_nil[res['dbencoding']]
|
34
|
+
@app_config[:db_config][:socket].should == empty_to_nil[res['dbsocket']]
|
35
|
+
end
|
@@ -14,6 +14,10 @@ When /^I create a double with "([^""]*)" as fullpath, "([^""]*)" as response con
|
|
14
14
|
last_response.should be_ok
|
15
15
|
end
|
16
16
|
|
17
|
+
Then /^I should get (#{CAPTURE_A_NUMBER}) in response status$/ do |status|
|
18
|
+
last_response.status.should == status
|
19
|
+
end
|
20
|
+
|
17
21
|
Then /^there should be (#{CAPTURE_A_NUMBER}) double with "([^"]*)" as fullpath and "([^"]*)" as response content$/ do |n, fullpath, content|
|
18
22
|
Double.where(:fullpath => fullpath, :content => content).count.should == n
|
19
23
|
end
|
data/features/support/env.rb
CHANGED
@@ -9,6 +9,7 @@ Spork.prefork do
|
|
9
9
|
require 'capybara/firebug'
|
10
10
|
require 'capybara/cucumber'
|
11
11
|
require 'database_cleaner'
|
12
|
+
require File.dirname(__FILE__) + '/world_helpers'
|
12
13
|
|
13
14
|
ENV['RACK_ENV'] = 'test'
|
14
15
|
|
@@ -32,14 +33,14 @@ Spork.prefork do
|
|
32
33
|
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
|
33
34
|
end
|
34
35
|
|
35
|
-
World(Capybara, Rack::Test::Methods, RackHeaderHack)
|
36
|
+
World(Capybara, Rack::Test::Methods, RackHeaderHack, WorldHelpers)
|
36
37
|
|
37
38
|
end
|
38
39
|
|
39
40
|
|
40
41
|
Spork.each_run do
|
41
42
|
require 'rest-assured/config'
|
42
|
-
|
43
|
+
RestAssured::Config.build(:adapter => 'mysql')
|
43
44
|
|
44
45
|
require 'rest-assured'
|
45
46
|
require 'rest-assured/client'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module WorldHelpers
|
5
|
+
def fake_start_rest_assured(options)
|
6
|
+
rest_assured_exec = File.expand_path '../../../bin/rest-assured', __FILE__
|
7
|
+
code = File.read rest_assured_exec
|
8
|
+
|
9
|
+
code.sub!(/(.*)/, "\\1\nENV['RACK_ENV'] = 'production'")
|
10
|
+
code.sub!(/require 'rest-assured'/, '')
|
11
|
+
code.sub!(/RestAssured::Application.run!/, 'puts AppConfig.to_yaml')
|
12
|
+
|
13
|
+
new_exec = "#{rest_assured_exec}_temp"
|
14
|
+
File.open(new_exec, 'w') do |file|
|
15
|
+
file.write code
|
16
|
+
end
|
17
|
+
|
18
|
+
`chmod +x #{new_exec}`
|
19
|
+
|
20
|
+
# this is 1.9.X version. So much more useful than 1.8 (uncommented). Sigh...
|
21
|
+
#config_yaml, stderr_str, status = Open3.capture3({'RACK_ENV' => 'production'}, new_exec, *options.split(' '))
|
22
|
+
config_yaml = nil
|
23
|
+
Open3.popen3(new_exec, *options.split(' ')) do |stdin, stdout, stderr|
|
24
|
+
config_yaml = stdout.read
|
25
|
+
end
|
26
|
+
|
27
|
+
`rm #{new_exec}`
|
28
|
+
|
29
|
+
YAML.load(config_yaml)
|
30
|
+
end
|
31
|
+
end
|
data/lib/rest-assured.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'sinatra/base'
|
3
3
|
require 'haml'
|
4
|
-
require 'sass'
|
5
4
|
require 'rack-flash'
|
6
5
|
require 'sinatra/partials'
|
7
|
-
require '
|
8
|
-
require 'rest-assured/init'
|
6
|
+
require 'rest-assured/config'
|
9
7
|
require 'rest-assured/models/double'
|
10
8
|
require 'rest-assured/models/redirect'
|
11
9
|
require 'rest-assured/models/request'
|
@@ -15,16 +13,10 @@ require 'rest-assured/routes/response'
|
|
15
13
|
|
16
14
|
module RestAssured
|
17
15
|
class Application < Sinatra::Base
|
18
|
-
set :environment, AppConfig[:environment]
|
19
|
-
set :port, AppConfig[:port]
|
20
16
|
|
21
|
-
|
17
|
+
include RestAssured::Config
|
22
18
|
|
23
|
-
|
24
|
-
alias_method :write, :<<
|
25
|
-
end
|
26
|
-
enable :logging
|
27
|
-
use Rack::CommonLogger, $app_logger
|
19
|
+
enable :method_override
|
28
20
|
|
29
21
|
enable :sessions
|
30
22
|
use Rack::Flash, :sweep => true
|
@@ -44,15 +36,6 @@ module RestAssured
|
|
44
36
|
include DoubleRoutes
|
45
37
|
include RedirectRoutes
|
46
38
|
|
47
|
-
#before do
|
48
|
-
#ActiveRecord::Base.clear_reloadable_connections!
|
49
|
-
#ActiveRecord::Base.clear_cache!
|
50
|
-
#end
|
51
|
-
|
52
|
-
get '/css/base.css' do
|
53
|
-
scss :base
|
54
|
-
end
|
55
|
-
|
56
39
|
%w{get post put delete}.each do |verb|
|
57
40
|
send verb, /.*/ do
|
58
41
|
Response.perform(self)
|
data/lib/rest-assured/config.rb
CHANGED
@@ -1,13 +1,138 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
require 'logger'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_support/core_ext/kernel/reporting'
|
4
|
+
|
5
|
+
module RestAssured
|
6
|
+
module Config
|
7
|
+
class ConfigHash < Hash
|
8
|
+
def initialize(default_values = {})
|
9
|
+
super()
|
10
|
+
self.merge!(default_values)
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(meth, *args)
|
14
|
+
meth = meth.to_s
|
15
|
+
|
16
|
+
if meth.sub!(/=/, '')
|
17
|
+
self[meth.to_sym] = args.first
|
18
|
+
else
|
19
|
+
self[meth.to_sym]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
::AppConfig = ConfigHash.new({
|
25
|
+
:port => 4578,
|
26
|
+
:environment => ENV['RACK_ENV'] || 'production',
|
27
|
+
:adapter => 'sqlite'
|
28
|
+
})
|
29
|
+
|
30
|
+
# this is meant to be called prior to include
|
31
|
+
def self.build(opts = {})
|
32
|
+
AppConfig.merge!(opts)
|
33
|
+
|
34
|
+
AppConfig.logfile ||= if AppConfig.environment == 'production'
|
35
|
+
'./rest-assured.log'
|
36
|
+
else
|
37
|
+
File.expand_path("../../../#{AppConfig.environment}.log", __FILE__)
|
38
|
+
end
|
39
|
+
build_db_config
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.included(klass)
|
43
|
+
init_logger
|
44
|
+
setup_db
|
45
|
+
|
46
|
+
klass.set :port, AppConfig.port
|
47
|
+
klass.set :environment, AppConfig.environment
|
48
|
+
|
49
|
+
klass.enable :logging
|
50
|
+
klass.use Rack::CommonLogger, AppConfig.logger
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.setup_db
|
56
|
+
setup_db_logging
|
57
|
+
connect_db
|
58
|
+
migrate_db
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.init_logger
|
62
|
+
Logger.class_eval do
|
63
|
+
alias_method :write, :<<
|
64
|
+
end
|
65
|
+
|
66
|
+
AppConfig.logger = Logger.new(AppConfig.logfile)
|
67
|
+
AppConfig.logger.level = Logger::DEBUG
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.setup_db_logging
|
71
|
+
raise "Init logger first" unless AppConfig.logger
|
72
|
+
|
73
|
+
# active record logging is purely internal
|
74
|
+
# thus disabling it for production
|
75
|
+
ActiveRecord::Base.logger = if AppConfig.environment == 'production'
|
76
|
+
Logger.new(dev_null)
|
77
|
+
else
|
78
|
+
AppConfig.logger
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.dev_null
|
83
|
+
test('e', '/dev/null') ? '/dev/null' : 'NUL:'
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.connect_db
|
87
|
+
ActiveRecord::Base.establish_connection AppConfig.db_config
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.migrate_db
|
91
|
+
migrate = lambda { ActiveRecord::Migrator.migrate(File.expand_path('../../../db/migrate', __FILE__)) }
|
92
|
+
|
93
|
+
if AppConfig[:environment] == 'production' && Kernel.respond_to?(:silence)
|
94
|
+
silence(:stdout, &migrate)
|
95
|
+
else
|
96
|
+
migrate.call
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.build_db_config
|
101
|
+
AppConfig.db_config = if AppConfig.adapter =~ /sqlite/i
|
102
|
+
default_database = if AppConfig.environment == 'production'
|
103
|
+
'./rest-assured.db'
|
104
|
+
else
|
105
|
+
File.expand_path("../../../db/#{AppConfig.environment}.db", __FILE__)
|
106
|
+
end
|
107
|
+
{
|
108
|
+
:adapter => 'sqlite3',
|
109
|
+
:database => AppConfig.database || default_database
|
110
|
+
}
|
111
|
+
elsif AppConfig.adapter =~ /mysql/i
|
112
|
+
default_database = if AppConfig.environment != 'production'
|
113
|
+
"rest_assured_#{AppConfig.environment}"
|
114
|
+
else
|
115
|
+
'rest_assured'
|
116
|
+
end
|
117
|
+
|
118
|
+
opts = {
|
119
|
+
:adapter => 'mysql',
|
120
|
+
:reconnect => true,
|
121
|
+
:user => AppConfig.user || 'root',
|
122
|
+
:database => AppConfig.database || default_database
|
123
|
+
}
|
124
|
+
|
125
|
+
opts[:password] = AppConfig.dbpass if AppConfig.dbpass
|
126
|
+
opts[:host] = AppConfig.dbhost if AppConfig.dbhost
|
127
|
+
opts[:port] = AppConfig.dbport if AppConfig.dbport
|
128
|
+
opts[:encoding] = AppConfig.dbencoding if AppConfig.dbencoding
|
129
|
+
opts[:socket] = AppConfig.dbsocket if AppConfig.dbsocket
|
130
|
+
opts
|
131
|
+
else
|
132
|
+
raise "Unsupported db adapter '#{AppConfig.adapter}'. Valid adapters are sqlite and mysql"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
data/lib/rest-assured/version.rb
CHANGED
File without changes
|
data/rest-assured.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency 'sinatra', '>= 1.3.1'
|
24
24
|
s.add_dependency 'rack-flash', '>= 0.1.2'
|
25
25
|
s.add_dependency 'haml', '>= 3.1.3'
|
26
|
-
s.add_dependency 'sass', '>= 3.1.8'
|
27
26
|
s.add_dependency 'activerecord', '~> 3.1.0'
|
28
27
|
s.add_dependency 'activeresource', '~> 3.1.0'
|
29
28
|
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path('../../lib/rest-assured/config', __FILE__)
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
describe RestAssured::Config do
|
5
|
+
#this is thoroughly covered in cucumber (since there it also serves documentation purposes)
|
6
|
+
#it 'builds config from user options'
|
7
|
+
|
8
|
+
it 'initializes logger' do
|
9
|
+
logger = double(:logger).as_null_object
|
10
|
+
AppConfig.stub(:logfile).and_return('test.log')
|
11
|
+
|
12
|
+
Logger.should_receive(:new).with('test.log').and_return(logger)
|
13
|
+
|
14
|
+
RestAssured::Config.init_logger
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'db setup' do
|
18
|
+
it 'connects db' do
|
19
|
+
RestAssured::Config.stub(:migrate_db) # so it does not complain
|
20
|
+
AppConfig.stub(:db_config).and_return('db_config')
|
21
|
+
|
22
|
+
ActiveRecord::Base.should_receive(:establish_connection).with('db_config')
|
23
|
+
|
24
|
+
RestAssured::Config.setup_db
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'active_record logging' do
|
28
|
+
let(:logger) { double(:logger).as_null_object }
|
29
|
+
|
30
|
+
before do
|
31
|
+
RestAssured::Config.stub(:migrate_db)
|
32
|
+
RestAssured::Config.stub(:connect_db)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is silenced in production' do
|
36
|
+
AppConfig.stub(:environment).and_return('production')
|
37
|
+
Logger.should_receive(:new).with(RestAssured::Config.dev_null).and_return(logger)
|
38
|
+
|
39
|
+
ActiveRecord::Base.should_receive(:logger=).with(logger)
|
40
|
+
|
41
|
+
RestAssured::Config.setup_db
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'is set to app logger for non production' do
|
45
|
+
AppConfig.stub(:environment).and_return('test')
|
46
|
+
AppConfig.stub(:logger).and_return(logger)
|
47
|
+
|
48
|
+
ActiveRecord::Base.should_receive(:logger=).with(logger)
|
49
|
+
|
50
|
+
RestAssured::Config.setup_db
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'runs migrations' do
|
55
|
+
RestAssured::Config.stub(:connect_db) # so it does not complain
|
56
|
+
|
57
|
+
ActiveRecord::Migrator.should_receive(:migrate)
|
58
|
+
|
59
|
+
RestAssured::Config.setup_db
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when included in RestAssured::Application' do
|
64
|
+
let(:app) { mock(:app).as_null_object }
|
65
|
+
|
66
|
+
before do
|
67
|
+
RestAssured::Config.build
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'initializes resources' do
|
71
|
+
RestAssured::Config.should_receive(:init_logger)
|
72
|
+
RestAssured::Config.should_receive(:setup_db)
|
73
|
+
|
74
|
+
RestAssured::Config.included(app)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'sets up environment' do
|
78
|
+
app.should_receive(:set).with(:environment, AppConfig.environment)
|
79
|
+
RestAssured::Config.included(app)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'sets up port' do
|
83
|
+
app.should_receive(:set).with(:port, AppConfig.port)
|
84
|
+
RestAssured::Config.included(app)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'connects logger' do
|
88
|
+
logger = double(:logger).as_null_object
|
89
|
+
AppConfig.stub(:logger).and_return(logger)
|
90
|
+
|
91
|
+
app.should_receive(:enable).with(:logging)
|
92
|
+
app.should_receive(:use).with(Rack::CommonLogger, logger)
|
93
|
+
|
94
|
+
RestAssured::Config.included(app)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-assured
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424037
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 0.2.0.
|
11
|
+
- 8
|
12
|
+
version: 0.2.0.rc8
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Artem Avetisyan
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-11-07 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: sinatra
|
@@ -67,26 +67,10 @@ dependencies:
|
|
67
67
|
version: 3.1.3
|
68
68
|
type: :runtime
|
69
69
|
version_requirements: *id003
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: sass
|
72
|
-
prerelease: false
|
73
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
|
-
requirements:
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
hash: 19
|
79
|
-
segments:
|
80
|
-
- 3
|
81
|
-
- 1
|
82
|
-
- 8
|
83
|
-
version: 3.1.8
|
84
|
-
type: :runtime
|
85
|
-
version_requirements: *id004
|
86
70
|
- !ruby/object:Gem::Dependency
|
87
71
|
name: activerecord
|
88
72
|
prerelease: false
|
89
|
-
requirement: &
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
90
74
|
none: false
|
91
75
|
requirements:
|
92
76
|
- - ~>
|
@@ -98,11 +82,11 @@ dependencies:
|
|
98
82
|
- 0
|
99
83
|
version: 3.1.0
|
100
84
|
type: :runtime
|
101
|
-
version_requirements: *
|
85
|
+
version_requirements: *id004
|
102
86
|
- !ruby/object:Gem::Dependency
|
103
87
|
name: activeresource
|
104
88
|
prerelease: false
|
105
|
-
requirement: &
|
89
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
106
90
|
none: false
|
107
91
|
requirements:
|
108
92
|
- - ~>
|
@@ -114,7 +98,7 @@ dependencies:
|
|
114
98
|
- 0
|
115
99
|
version: 3.1.0
|
116
100
|
type: :runtime
|
117
|
-
version_requirements: *
|
101
|
+
version_requirements: *id005
|
118
102
|
description:
|
119
103
|
email:
|
120
104
|
- artem.avetisyan@bbc.co.uk
|
@@ -147,24 +131,25 @@ files:
|
|
147
131
|
- db/migrate/20111016174101_rename_method_to_verb.rb
|
148
132
|
- db/migrate/20111021113953_add_status_to_doubles.rb
|
149
133
|
- features/call_history.feature
|
134
|
+
- features/command_line_options.feature
|
150
135
|
- features/doubles_via_api.feature
|
151
136
|
- features/doubles_via_ui.feature
|
152
137
|
- features/redirect_rules_via_api.feature
|
153
138
|
- features/redirect_rules_via_ui.feature
|
154
139
|
- features/step_definitions/call_history_steps.rb
|
140
|
+
- features/step_definitions/command_line_options_steps.rb
|
155
141
|
- features/step_definitions/doubles_steps.rb
|
156
|
-
- features/step_definitions/persistence_steps.rb
|
157
142
|
- features/step_definitions/redirect_rules_steps.rb
|
158
143
|
- features/step_definitions/support/numeric_transforms.rb
|
159
144
|
- features/support/env.rb
|
160
145
|
- features/support/selenium-fix.rb
|
161
146
|
- features/support/test-server.rb
|
147
|
+
- features/support/world_helpers.rb
|
162
148
|
- lib/active_record/leaky_connections_patch.rb
|
163
149
|
- lib/rest-assured.rb
|
164
150
|
- lib/rest-assured/client.rb
|
165
151
|
- lib/rest-assured/client/resources.rb
|
166
152
|
- lib/rest-assured/config.rb
|
167
|
-
- lib/rest-assured/init.rb
|
168
153
|
- lib/rest-assured/models/double.rb
|
169
154
|
- lib/rest-assured/models/redirect.rb
|
170
155
|
- lib/rest-assured/models/request.rb
|
@@ -173,6 +158,7 @@ files:
|
|
173
158
|
- lib/rest-assured/routes/response.rb
|
174
159
|
- lib/rest-assured/version.rb
|
175
160
|
- lib/sinatra/partials.rb
|
161
|
+
- public/css/base.css
|
176
162
|
- public/css/grid.inuit.css
|
177
163
|
- public/css/inuit.css
|
178
164
|
- public/css/jquery.jgrowl.css
|
@@ -190,6 +176,7 @@ files:
|
|
190
176
|
- public/javascript/jquery.jgrowl_minimized.js
|
191
177
|
- rest-assured.gemspec
|
192
178
|
- spec/client/resource_double_spec.rb
|
179
|
+
- spec/config_spec.rb
|
193
180
|
- spec/custom_matchers.rb
|
194
181
|
- spec/functional/double_routes_spec.rb
|
195
182
|
- spec/functional/redirect_routes_spec.rb
|
@@ -198,7 +185,6 @@ files:
|
|
198
185
|
- spec/models/redirect_spec.rb
|
199
186
|
- spec/models/request_spec.rb
|
200
187
|
- spec/spec_helper.rb
|
201
|
-
- views/base.scss
|
202
188
|
- views/doubles/_form.haml
|
203
189
|
- views/doubles/edit.haml
|
204
190
|
- views/doubles/index.haml
|
@@ -247,19 +233,22 @@ specification_version: 3
|
|
247
233
|
summary: A tool for high level mocking/stubbing HTTP based REST services
|
248
234
|
test_files:
|
249
235
|
- features/call_history.feature
|
236
|
+
- features/command_line_options.feature
|
250
237
|
- features/doubles_via_api.feature
|
251
238
|
- features/doubles_via_ui.feature
|
252
239
|
- features/redirect_rules_via_api.feature
|
253
240
|
- features/redirect_rules_via_ui.feature
|
254
241
|
- features/step_definitions/call_history_steps.rb
|
242
|
+
- features/step_definitions/command_line_options_steps.rb
|
255
243
|
- features/step_definitions/doubles_steps.rb
|
256
|
-
- features/step_definitions/persistence_steps.rb
|
257
244
|
- features/step_definitions/redirect_rules_steps.rb
|
258
245
|
- features/step_definitions/support/numeric_transforms.rb
|
259
246
|
- features/support/env.rb
|
260
247
|
- features/support/selenium-fix.rb
|
261
248
|
- features/support/test-server.rb
|
249
|
+
- features/support/world_helpers.rb
|
262
250
|
- spec/client/resource_double_spec.rb
|
251
|
+
- spec/config_spec.rb
|
263
252
|
- spec/custom_matchers.rb
|
264
253
|
- spec/functional/double_routes_spec.rb
|
265
254
|
- spec/functional/redirect_routes_spec.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
Given /^I (?:re)?start service without \-\-database option$/ do
|
2
|
-
AppConfig[:database] = ':memory:' #default value
|
3
|
-
load 'rest-assured/init.rb'
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /^I should get (#{CAPTURE_A_NUMBER}) in response status$/ do |status|
|
7
|
-
last_response.status.should == status
|
8
|
-
end
|
9
|
-
|
10
|
-
Given /^I (?:re)?start service with \-\-database "([^"]*)" option$/ do |db_path|
|
11
|
-
AppConfig[:database] = db_path
|
12
|
-
load 'rest-assured/init.rb'
|
13
|
-
end
|
data/lib/rest-assured/init.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
#require 'active_record/leaky_connections_patch'
|
3
|
-
#require 'active_record/sqlite_transaction_hell_patch'
|
4
|
-
require 'rest-assured/config'
|
5
|
-
require 'logger'
|
6
|
-
require 'active_support/core_ext/kernel/reporting'
|
7
|
-
|
8
|
-
module RestAssured
|
9
|
-
class Init
|
10
|
-
def self.init!
|
11
|
-
setup_logger
|
12
|
-
connect_db
|
13
|
-
migrate_db
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
def self.build_db_config
|
18
|
-
if AppConfig[:adapter] =~ /sqlite/i
|
19
|
-
AppConfig[:database] ||= if AppConfig[:environment] == 'production'
|
20
|
-
'./rest-assured.db'
|
21
|
-
else
|
22
|
-
File.expand_path("../../../db/#{AppConfig[:environment]}.db", __FILE__)
|
23
|
-
end
|
24
|
-
{
|
25
|
-
:adapter => 'sqlite3',
|
26
|
-
:database => AppConfig[:database]
|
27
|
-
}
|
28
|
-
elsif AppConfig[:adapter] =~ /mysql/i
|
29
|
-
AppConfig[:database] ||= if AppConfig[:environment] != 'production'
|
30
|
-
"rest_assured_#{AppConfig[:environment]}"
|
31
|
-
else
|
32
|
-
'rest_assured'
|
33
|
-
end
|
34
|
-
AppConfig[:db_user] ||= 'root'
|
35
|
-
|
36
|
-
{
|
37
|
-
:adapter => 'mysql',
|
38
|
-
:reconnect => true,
|
39
|
-
:user => AppConfig[:db_user],
|
40
|
-
:password => AppConfig[:db_password],
|
41
|
-
:database => AppConfig[:database]
|
42
|
-
}
|
43
|
-
else
|
44
|
-
raise "Unsupported db adapter '#{AppConfig[:adapter]}'. Valid adapters are sqlite and mysql"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.connect_db
|
49
|
-
config = build_db_config
|
50
|
-
ActiveRecord::Base.establish_connection config
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.migrate_db
|
54
|
-
migrate = lambda { ActiveRecord::Migrator.migrate(File.expand_path('../../../db/migrate', __FILE__)) }
|
55
|
-
|
56
|
-
if AppConfig[:environment] == 'production' && Kernel.respond_to?(:silence)
|
57
|
-
silence(:stdout, &migrate)
|
58
|
-
else
|
59
|
-
migrate.call
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.setup_logger
|
64
|
-
$app_logger = Logger.new(AppConfig[:log_file])
|
65
|
-
$app_logger.level = Logger::DEBUG
|
66
|
-
|
67
|
-
# active record logging is purely internal
|
68
|
-
# thus disabling it for production
|
69
|
-
ActiveRecord::Base.logger = if AppConfig[:environment] == 'production'
|
70
|
-
Logger.new(test('e', '/dev/null') ? '/dev/null' : 'NUL:')
|
71
|
-
else
|
72
|
-
$app_logger
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
Init.init!
|
78
|
-
end
|