rest-assured 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +4 -0
  3. data/README.markdown +12 -19
  4. data/db/development.db +0 -0
  5. data/db/test.db +0 -0
  6. data/features/ruby_api/test_server.feature +4 -4
  7. data/features/step_definitions/command_line_options_steps.rb +1 -1
  8. data/features/step_definitions/doubles_steps.rb +1 -1
  9. data/features/support/env.rb +3 -3
  10. data/features/support/world_helpers.rb +2 -8
  11. data/lib/rest-assured/api/app_session.rb +6 -1
  12. data/lib/rest-assured/api/server.rb +2 -14
  13. data/lib/rest-assured/config.rb +10 -3
  14. data/lib/rest-assured/models/double.rb +0 -2
  15. data/lib/rest-assured/models/redirect.rb +1 -3
  16. data/lib/rest-assured/routes/double.rb +2 -2
  17. data/lib/rest-assured/version.rb +1 -1
  18. data/spec/api/app_session_spec.rb +11 -5
  19. data/spec/api/resource_double_spec.rb +14 -13
  20. data/spec/api/server_spec.rb +38 -43
  21. data/spec/config_spec.rb +3 -3
  22. data/spec/functional/double_routes_spec.rb +53 -53
  23. data/spec/functional/redirect_routes_spec.rb +27 -27
  24. data/spec/functional/response_spec.rb +18 -18
  25. data/spec/models/double_spec.rb +22 -27
  26. data/spec/models/redirect_spec.rb +12 -15
  27. data/spec/models/request_spec.rb +4 -4
  28. data/spec/port_explorer_spec.rb +3 -3
  29. data/spec/spec_helper.rb +30 -22
  30. metadata +24 -37
  31. data/.gitignore +0 -9
  32. data/.rspec +0 -1
  33. data/.travis.yml +0 -15
  34. data/Gemfile +0 -36
  35. data/Gemfile.lock +0 -176
  36. data/Guardfile +0 -10
  37. data/Procfile +0 -1
  38. data/Rakefile +0 -2
  39. data/bin/console +0 -11
  40. data/bin/heroku_runner +0 -27
  41. data/cucumber.yml +0 -3
  42. data/features/support/test-server.rb +0 -35
  43. data/rest-assured.gemspec +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4be619d9752d4b3fc3ef2f4755c2f1de691d83b
4
- data.tar.gz: c289e34540a93ae862f2bd2087f495d4ae993968
3
+ metadata.gz: 320425382c9e1d8d34f2a6d6daa53bf7e6af42f6
4
+ data.tar.gz: 5e9c14601074ee5b5ee589617b9d2e0be387fe9a
5
5
  SHA512:
6
- metadata.gz: 0df823b94ad412f0c966155ef635fc19121a64d5b673f4b79c48459fd4c178a986b5ad274f2c932576df2b952ec4731168bf904b321282a1135416550c4d5434
7
- data.tar.gz: 9c4289f4b76be49c696b84ccc263a00375e118177f02368b69c86f8b9a702644ea30bb107cda78bb5a7d936963cd8eb441787e0a2c3d58c968696f4cc78f3be4
6
+ metadata.gz: 805ce441b6dc113fe988e691533ecce3609798163e60875eeeb1c1640ecc0bc60ead758129a7dcec17012a3b3caab7623bf01d6af8a1893a88ca664fa74c5eaf
7
+ data.tar.gz: 1640ad76091994a6ff2794f5df9394a88158aaad556551da207ae2085b04bbd9d11ab8d44ea820707ae6c977f957d526b5f59df456138c5e2a960d1ff127de81
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 2.0.1 (9 May 2015)
2
+
3
+ - update dependencies
4
+
1
5
  2.0.0 (1 Feb 2014)
2
6
 
3
7
  - discontinue ruby 1.8.7 support
@@ -2,29 +2,31 @@
2
2
 
3
3
  [![Build status](https://secure.travis-ci.org/artemave/REST-assured.png)](https://travis-ci.org/artemave/REST-assured)
4
4
  [![Gem Version](https://badge.fury.io/rb/rest-assured.png)](http://badge.fury.io/rb/rest-assured)
5
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/artemave/rest-assured/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
6
5
 
7
6
  ## Overview
8
7
 
9
8
  Stub/spy http(s) based external dependencies in your integration/acceptance tests.
10
9
 
10
+ ## Description
11
+
11
12
  In a nutshell, you can:
12
13
 
13
14
  * replace external data sources with predefined data (stubbing)
14
15
  * verify requests to external services (spying)
15
16
  * simulate different behavior of external services using web UI; useful in development
16
17
 
17
- Here is how it works. REST-assured starts a web server whose routes can be configured at runtime (via ruby client library or REST api) to respond to any request with arbitrary content, status, headers, etc. Configure api endpoints of the application under test to point to REST-assured instead of real services. Now in tests use the REST-assured api to create routes (doubles) that match requests your application is firing. Either to stub content or to verify various aspects of how your application requests dependencies (headers, payload, etc).
18
+ REST-assured runs in a standalone process. It can be configured at runtime (via ruby client library or REST api) to respond to any request with arbitrary content, status, headers, etc.
19
+
20
+ The idea is that in "test" environment your app is making calls to REST-assured rather than to real external services.
18
21
 
19
- <br>
20
- [Playground](http://rest-assured.herokuapp.com) (might take few seconds to load while heroku is taking off)
22
+ [Playground](http://fakesh.it/)
21
23
 
22
24
  [Example project](https://github.com/artemave/REST-assured-example)
23
25
 
24
26
 
25
27
  ## Set up
26
28
 
27
- You are going to need ruby >= 1.8.7 on Linux/MacOS. Also, one of sqlite3, postgres or mysql.
29
+ You are going to need ruby >= 1.9.2 on Linux/MacOS. Also, one of sqlite3, postgres or mysql.
28
30
 
29
31
  ### In ruby project
30
32
 
@@ -65,24 +67,15 @@ This starts up an instance of rest-assured on port 4578. It is accessible via RE
65
67
 
66
68
  Various options (such as ssl, port, db credentials, etc.) are available through command line options. Check out `rest-assured -h` to see what they are.
67
69
 
68
- You can also deploy it to heroku:
69
-
70
- $ git clone git://github.com/artemave/REST-assured.git
71
- $ cd REST-assured
72
-
73
- $ gem install heroku
74
- $ heroku login # assuming you already have an account
75
- $ heroku create --stack cedar
76
-
77
- $ git push heroku master
70
+ You can also [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
78
71
 
79
72
  ## Usage
80
73
 
81
- REST-assured is all about doubles. Double is a stub/spy of HTTP request. Create one that has the same request fullpath and method as the one your app is sending to a service it depends on (e.g. twitter) and then convience your app that REST-assured is that dependency (e.g. by swapping endpoints - twitter.com to localhost:4578 - in test environment).
74
+ REST-assured can do two things: respond to a particular path and method (e.g. GET /stuff/v2?thing=1) and redirect requests based on a pattern (e.g. all /foo\* will redirect to http://example.com/bar). Both of these are available to create/read/delete in runtime via api.
82
75
 
83
- ### Ruby Client
76
+ ### Ruby API
84
77
 
85
- REST-assured provides client library to work with doubles. Check out 'Ruby API' section in [live documentation](https://www.relishapp.com/artemave/rest-assured) for full reference.
78
+ REST-assured provides ruby client library to work with doubles (but not redirects). Check out 'Ruby API' section in [live documentation](https://www.relishapp.com/artemave/rest-assured) for full reference.
86
79
 
87
80
  Create double:
88
81
 
@@ -121,7 +114,7 @@ RestClient.delete "#{RestAssured::Server.address}/doubles/all"
121
114
 
122
115
  ### REST API
123
116
 
124
- For those using REST-assured from non-ruby environments.
117
+ For using REST-assured from non-ruby environments.
125
118
 
126
119
  #### Create double
127
120
 
Binary file
Binary file
@@ -12,7 +12,7 @@ Feature: test server
12
12
  """
13
13
  Then rest-assured server should be running:
14
14
  """
15
- RestAssured::Server.should be_up
15
+ expect(RestAssured::Server.up?).to eq true
16
16
  """
17
17
 
18
18
  Scenario: start asyncronously (so that other heavy setup - e.g. firefox startup - can be done in parallel)
@@ -23,12 +23,12 @@ Feature: test server
23
23
  """
24
24
  Then rest-assured server should not be running:
25
25
  """
26
- RestAssured::Server.should_not be_up
26
+ expect(RestAssured::Server.up?).to eq false
27
27
  """
28
28
  When it finally comes up
29
29
  Then rest-assured server should be running:
30
30
  """
31
- RestAssured::Server.should be_up
31
+ expect(RestAssured::Server.up?).to eq true
32
32
  """
33
33
 
34
34
  Scenario: stop rest-assured server
@@ -39,5 +39,5 @@ Feature: test server
39
39
  """
40
40
  Then it should be stopped:
41
41
  """
42
- RestAssured::Server.should_not be_up
42
+ expect(RestAssured::Server.up?).to eq false
43
43
  """
@@ -21,7 +21,7 @@ Then /^database options should be:$/ do |table|
21
21
  empty_to_nil = lambda do |string|
22
22
  string.try(:empty?) ? nil : string
23
23
  end
24
-
24
+
25
25
  @app_config[:db_config][:adapter].should == res['adapter']
26
26
  @app_config[:db_config][:database].should == res['dbname']
27
27
  @app_config[:db_config][:username].should == res['dbuser']
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  Then /^I should be able to get json representation of that double from response$/ do
18
18
  d = RestAssured::Models::Double.last
19
- MultiJson.load( @create_a_double_response ).should == MultiJson.load( d.to_json )
19
+ JSON.load( @create_a_double_response ).should == MultiJson.load( d.to_json )
20
20
  end
21
21
 
22
22
  Then /^I should get (#{CAPTURE_A_NUMBER}) in response status$/ do |status|
@@ -33,19 +33,19 @@ end
33
33
  World(Capybara, Rack::Test::Methods, RackHeaderHack, WorldHelpers, Anticipate)
34
34
 
35
35
  require 'rest-assured/config'
36
- db_opts = { :adapter => 'mysql' }
36
+ db_opts = { :adapter => 'postgresql' }
37
37
  RestAssured::Config.build(db_opts)
38
38
 
39
39
  require 'rest-assured'
40
40
  require 'shoulda-matchers'
41
41
 
42
- RestAssured::Server.start(db_opts.merge(:port => 9876))
42
+ RestAssured::Server.start(db_opts.merge(:port => 19876))
43
43
 
44
44
  Before "@api_server" do
45
45
  RestAssured::Server.stop
46
46
  end
47
47
  After "@api_server" do
48
- RestAssured::Server.start(db_opts.merge(:port => 9876))
48
+ RestAssured::Server.start(db_opts.merge(:port => 19876))
49
49
  end
50
50
 
51
51
  require 'rest-assured/application'
@@ -6,9 +6,8 @@ module WorldHelpers
6
6
  rest_assured_exec = File.expand_path '../../../bin/rest-assured', __FILE__
7
7
  code = File.read rest_assured_exec
8
8
 
9
- code.sub!(/(.*)/, "\\1\nENV['RACK_ENV'] = 'production'")
10
9
  code.sub!(/require 'rest-assured\/application'/, '')
11
- code.sub!(/RestAssured::Application.run!.*/m, 'puts AppConfig.to_yaml')
10
+ code.sub!(/RestAssured::Application.run!.*/m, 'require "yaml"; puts AppConfig.to_yaml')
12
11
 
13
12
  new_exec = "#{rest_assured_exec}_temp"
14
13
  File.open(new_exec, 'w') do |file|
@@ -17,12 +16,7 @@ module WorldHelpers
17
16
 
18
17
  `chmod +x #{new_exec}`
19
18
 
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
19
+ config_yaml, _, _ = Open3.capture3({'RACK_ENV' => 'production'}, new_exec, *options.split(' '))
26
20
 
27
21
  `rm #{new_exec}`
28
22
 
@@ -3,11 +3,16 @@ require 'childprocess'
3
3
  module RestAssured
4
4
  class AppSession
5
5
  def initialize
6
- @child = ChildProcess.build('rest-assured', *Config.to_cmdargs)
6
+ @child = ChildProcess.build('bin/rest-assured', *Config.to_cmdargs)
7
+ @child.cwd = File.expand_path '../../../..', __FILE__
7
8
  @child.io.inherit!
8
9
  @child.start
9
10
  end
10
11
 
12
+ def stop
13
+ @child.stop while @child.alive?
14
+ end
15
+
11
16
  def method_missing(*args)
12
17
  @child.send(*args)
13
18
  end
@@ -11,8 +11,6 @@ module RestAssured
11
11
  include Singleton
12
12
 
13
13
  at_exit do
14
- # I don't know why, but without this puts() at_exit is triggered on Ctrl-C when running in spork
15
- puts ''
16
14
  instance.stop if instance
17
15
  end
18
16
 
@@ -39,21 +37,11 @@ module RestAssured
39
37
  end
40
38
 
41
39
  def stop
42
- @session.try(:stop)
43
-
44
- 10.times do
45
- if up?
46
- sleep 0.5
47
- next
48
- else
49
- return
50
- end
51
- end
52
- raise "Failed to stop RestAssured server"
40
+ @session.try :stop
53
41
  end
54
42
 
55
43
  def up?
56
- !!@session && @session.alive? && !Utils::PortExplorer.port_free?(AppConfig.port)
44
+ !!@session && @session.alive? && !Utils::PortExplorer.port_free?(AppConfig.port)
57
45
  end
58
46
 
59
47
  def self.method_missing(*args)
@@ -103,9 +103,15 @@ module RestAssured
103
103
 
104
104
  def self.migrate_db
105
105
  migrate = lambda { ActiveRecord::Migrator.migrate(File.expand_path('../../../db/migrate', __FILE__)) }
106
+ silence_stdout = lambda do |&thing|
107
+ original_stdout = $stdout
108
+ $stdout = File.open(File::NULL, "w")
109
+ thing.call
110
+ $stdout = original_stdout
111
+ end
106
112
 
107
- if AppConfig[:environment] == 'production' && Kernel.respond_to?(:silence)
108
- silence(:stdout, &migrate)
113
+ if AppConfig[:environment] == 'production'
114
+ silence_stdout.call(&migrate)
109
115
  else
110
116
  migrate.call
111
117
  end
@@ -135,7 +141,8 @@ module RestAssured
135
141
  opts = {
136
142
  :adapter => 'postgresql',
137
143
  :username => AppConfig.user || 'root',
138
- :database => AppConfig.database || default_database
144
+ :database => AppConfig.database || default_database,
145
+ :pool => 20
139
146
  }
140
147
  if adapter =~ /mysql/
141
148
  adapter = RUBY_PLATFORM == "java" ? 'jdbcmysql' : 'mysql2'
@@ -3,8 +3,6 @@ require 'net/http'
3
3
  module RestAssured
4
4
  module Models
5
5
  class Double < ActiveRecord::Base
6
- attr_accessible :fullpath, :content, :description, :verb, :status, :response_headers
7
-
8
6
  serialize :response_headers, Hash
9
7
 
10
8
  VERBS = %w{GET POST PUT DELETE HEAD PATCH}
@@ -1,11 +1,9 @@
1
1
  module RestAssured
2
2
  module Models
3
3
  class Redirect < ActiveRecord::Base
4
- attr_accessible :pattern, :to, :position
5
-
6
4
  validates_presence_of :pattern, :to
7
5
 
8
- scope :ordered, order('position')
6
+ scope :ordered, -> { order('position') }
9
7
 
10
8
  before_create :assign_position
11
9
 
@@ -43,7 +43,7 @@ module RestAssured
43
43
  router.post /^\/doubles(\.json)?$/ do |needs_json|
44
44
  begin
45
45
  data = request.body.read
46
- d = MultiJson.load(data)['double']
46
+ d = JSON.load(data)
47
47
 
48
48
  # fix acitve resource dumbness
49
49
  if d['response_headers'] and d['response_headers']['response_headers']
@@ -54,7 +54,7 @@ module RestAssured
54
54
  params.slice(*%w[fullpath content description verb status response_headers])
55
55
  end
56
56
 
57
- @double = Models::Double.create(d)
57
+ @double = Models::Double.create(d)
58
58
 
59
59
  if needs_json
60
60
  if @double.errors.present?
@@ -1,3 +1,3 @@
1
1
  module RestAssured
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
@@ -4,17 +4,23 @@ require File.expand_path('../../../lib/rest-assured/api/app_session', __FILE__)
4
4
 
5
5
  module RestAssured
6
6
  describe AppSession do
7
+ let(:child) do
8
+ double(io: double, :cwd= => double)
9
+ end
10
+
7
11
  it 'starts application in childprocess' do
8
12
  cmdargs = %w{-d :memory: -p 6666}
9
- Config.stub(:to_cmdargs => cmdargs)
13
+ allow(Config).to receive_messages(:to_cmdargs => cmdargs)
14
+
15
+ expect(ChildProcess).to receive(:build).with('bin/rest-assured', *cmdargs).and_return(child)
10
16
 
11
- ChildProcess.should_receive(:build).with('rest-assured', *cmdargs).and_return(child = double(:io => double))
17
+ expect(child).to receive(:cwd=)
12
18
 
13
19
  state = ''
14
- child.io.should_receive(:inherit!) do
15
- state.should_not == 'started'
20
+ expect(child.io).to receive(:inherit!) do
21
+ expect(state).not_to eq('started')
16
22
  end
17
- child.should_receive(:start) do
23
+ expect(child).to receive(:start) do
18
24
  state << 'started'
19
25
  end
20
26
 
@@ -6,24 +6,25 @@ module RestAssured
6
6
  before(:all) do
7
7
  Server.start(DB_OPTS.merge(:port => 9877))
8
8
  end
9
+
9
10
  after(:all) do
10
11
  Server.stop
11
12
  end
12
13
 
13
- it { should be_kind_of ActiveResource::Base }
14
+ it { is_expected.to be_kind_of ActiveResource::Base }
14
15
 
15
16
  it 'creates new double' do
16
- d = Double.create :fullpath => '/some/api', :content => 'content'
17
- Models::Double.where(:fullpath => d.fullpath, :content => d.content).should exist
17
+ d = Models::Double.create! :fullpath => '/some/api', :content => 'content'
18
+ expect(Models::Double.where(:fullpath => d.fullpath, :content => d.content)).to exist
18
19
  end
19
20
 
20
21
  it 'finds exising double' do
21
- d = Models::Double.create :fullpath => '/some/api', :content => 'content'
22
+ d = Models::Double.create! :fullpath => '/some/api', :content => 'content'
22
23
 
23
24
  dd = Double.find(d.id)
24
25
 
25
- dd.fullpath.should == d.fullpath
26
- dd.content.should == d.content
26
+ expect(dd.fullpath).to eq(d.fullpath)
27
+ expect(dd.content).to eq(d.content)
27
28
  end
28
29
 
29
30
  it 'shows request history' do
@@ -32,10 +33,10 @@ module RestAssured
32
33
  d.requests << Models::Request.create(:rack_env => 'different rack_env', :body => 'other body', :params => 'more params')
33
34
 
34
35
  dd = Double.find(d.id)
35
- dd.requests.size.should == 2
36
- dd.requests.first.rack_env.should == 'rack_env json'
37
- dd.requests.first.params.should == 'params'
38
- dd.requests.last.body.should == 'other body'
36
+ expect(dd.requests.size).to eq(2)
37
+ expect(dd.requests.first.rack_env).to eq('rack_env json')
38
+ expect(dd.requests.first.params).to eq('params')
39
+ expect(dd.requests.last.body).to eq('other body')
39
40
  end
40
41
 
41
42
  context 'when waits requests' do
@@ -56,13 +57,13 @@ module RestAssured
56
57
 
57
58
  dd.wait_for_requests(2)
58
59
 
59
- dd.requests.count.should >= 2
60
+ expect(dd.requests.count).to be >= 2
60
61
  end
61
62
 
62
63
  it 'raises exception if requests have not happened within timeout' do
63
64
  d = Models::Double.create :fullpath => '/some/api', :content => 'content'
64
65
  dd = Double.find(d.id)
65
- dd.stub(:sleep)
66
+ allow(dd).to receive(:sleep)
66
67
 
67
68
  @t = Thread.new do
68
69
  2.times do
@@ -71,7 +72,7 @@ module RestAssured
71
72
  end
72
73
 
73
74
  sleep 0.5
74
- lambda { dd.wait_for_requests(3) }.should raise_error(MoreRequestsExpected, 'Expected 3 requests. Got 2.')
75
+ expect { dd.wait_for_requests(3) }.to raise_error(MoreRequestsExpected, 'Expected 3 requests. Got 2.')
75
76
  end
76
77
  end
77
78
  end
@@ -3,95 +3,91 @@ require File.expand_path('../../../lib/rest-assured/api/server', __FILE__)
3
3
 
4
4
  module RestAssured
5
5
  describe Server do
6
- around do |example|
7
- Server.reset_instance
8
- example.run
9
- Server.reset_instance
6
+ before do
7
+ allow(AppSession).to receive(:new).and_return(session)
10
8
  end
11
9
 
10
+ after do
11
+ Singleton.__init__(Server)
12
+ end
13
+
14
+ let (:session) { double.as_null_object }
15
+
12
16
  it 'khows when it is up' do
13
- AppSession.stub(:new).and_return(session = double(:alive? => true).as_null_object)
14
- Utils::PortExplorer.stub(:port_free? => false)
17
+ allow(session).to receive(:alive?).and_return(true)
18
+ allow(Utils::PortExplorer).to receive(:port_free?).and_return(false)
15
19
 
16
20
  Server.start
17
- Server.up?.should == true
21
+ expect(Server.up?).to eq true
18
22
  end
19
23
 
20
24
  context 'knows that it is NOT up' do
21
25
  it 'if it has not been started' do
22
- Server.up?.should == false
26
+ expect(Server.up?).to eq false
23
27
  end
24
28
 
25
29
  it 'if it is starting at the moment' do
26
- AppSession.stub(:new).and_return(session = double(:alive? => true).as_null_object)
27
- Utils::PortExplorer.stub(:port_free? => true)
30
+ allow(session).to receive(:alive?).and_return(true)
31
+ allow(Utils::PortExplorer).to receive(:port_free?).and_return(true)
28
32
  Server.start!
29
33
 
30
- Server.up?.should == false
34
+ expect(Server.up?).to eq false
31
35
  end
32
36
  end
33
37
 
34
38
  context 'when starts' do
35
39
  it 'makes sure no previous session is running' do
36
- session = double.as_null_object
37
- session.stub(:alive?).and_return(true, false)
38
- Utils::PortExplorer.stub(:port_free? => false)
39
- AppSession.stub(:new).and_return(session)
40
+ allow(session).to receive(:alive?).and_return(true, false)
41
+ allow(Utils::PortExplorer).to receive(:port_free?).and_return(false)
40
42
 
41
- session.should_receive(:stop).once
43
+ expect(session).to receive(:stop).once
42
44
  Server.start!
43
45
  Server.start!
44
46
  end
45
47
 
46
48
  it 'builds application config' do
47
- AppSession.stub(:new).as_null_object
48
-
49
49
  opts = { :port => 34545, :database => ':memory:' }
50
50
 
51
- Config.should_receive(:build).with(opts)
51
+ expect(Config).to receive(:build).with(opts)
52
52
  Server.start!(opts)
53
53
  end
54
54
 
55
55
  context 'sets up server address' do
56
- before do
57
- AppSession.stub(:new).as_null_object
58
- end
59
-
60
56
  it 'uses 127.0.0.1 as hostname' do
61
- RestAssured::Double.should_receive(:site=).with(/127\.0\.0\.1/)
57
+ expect(RestAssured::Double).to receive(:site=).with(/127\.0\.0\.1/)
62
58
  Server.start!
63
- Server.address.should =~ /127\.0\.0\.1/
59
+ expect(Server.address).to match(/127\.0\.0\.1/)
64
60
  end
65
61
 
66
62
  it 'uses port from config' do
67
- RestAssured::Double.should_receive(:site=).with(/#{AppConfig.port}/)
63
+ expect(RestAssured::Double).to receive(:site=).with(/#{AppConfig.port}/)
68
64
  Server.start!
69
- Server.address.should =~ /#{AppConfig.port}/
65
+ expect(Server.address).to match(/#{AppConfig.port}/)
70
66
  end
71
67
 
72
68
  it 'uses http by default' do
73
- RestAssured::Double.should_receive(:site=).with(/http[^s]/)
69
+ expect(RestAssured::Double).to receive(:site=).with(/http[^s]/)
74
70
  Server.start!
75
- Server.address.should =~ /http[^s]/
71
+ expect(Server.address).to match(/http[^s]/)
76
72
  end
77
73
 
78
74
  it 'uses https if ssl is set in config' do
79
75
  AppConfig.ssl = true
80
- RestAssured::Double.should_receive(:site=).with(/https/)
76
+ expect(RestAssured::Double).to receive(:site=).with(/https/)
81
77
  Server.start!
82
- Server.address.should =~ /https/
78
+ expect(Server.address).to match(/https/)
83
79
  end
84
80
  end
85
81
 
86
82
  describe 'async/sync start' do
87
83
  before do
88
- AppSession.stub(:new).and_return(session = double(:alive? => false).as_null_object)
89
- Utils::PortExplorer.stub(:port_free? => true)
84
+ allow(session).to receive(:alive?).and_return(false)
85
+ allow(Utils::PortExplorer).to receive(:port_free?).and_return(true)
90
86
 
91
87
  @t = Thread.new do
92
88
  sleep 0.5
93
- session.stub(:alive?).and_return(true)
94
- Utils::PortExplorer.stub(:port_free? => false)
89
+ allow(session).to receive(:alive?).and_return(true)
90
+ allow(Utils::PortExplorer).to receive(:port_free?).and_return(false)
95
91
  end
96
92
  end
97
93
 
@@ -101,31 +97,30 @@ module RestAssured
101
97
 
102
98
  it 'does not wait for Application to come up' do
103
99
  Server.start!
104
- Server.up?.should == false
100
+ expect(Server.up?).to eq false
105
101
  end
106
102
 
107
103
  it 'can wait until Application is up before passing control' do
108
104
  Server.start
109
- Server.up?.should == true
105
+ expect(Server.up?).to eq true
110
106
  end
111
107
  end
112
108
  end
113
109
 
114
110
  context 'when stopped' do
115
111
  it 'stops application subprocess' do
116
- AppSession.stub(:new).and_return(session = double(:alive? => false))
112
+ allow(session).to receive(:alive?).and_return(false)
117
113
  Server.start!
118
114
 
119
- session.should_receive(:stop)
115
+ expect(session).to receive(:stop)
120
116
  Server.stop
121
117
  end
122
118
  end
123
119
 
124
120
  it 'stops application subprocess when current process exits' do
125
121
  res_file = Tempfile.new('res')
126
- AppSession.stub(:new).and_return(session = double.as_null_object)
127
- session.stub(:alive?).and_return(false)
128
- session.stub(:stop) do
122
+ allow(session).to receive(:alive?).and_return(false)
123
+ allow(session).to receive(:stop) do
129
124
  res_file.write "stopped"
130
125
  res_file.rewind
131
126
  end
@@ -133,7 +128,7 @@ module RestAssured
133
128
  Server.start!
134
129
  end
135
130
  Process.wait
136
- res_file.read.should == 'stopped'
131
+ expect(res_file.read).to eq 'stopped'
137
132
  end
138
133
  end
139
134
  end