rest-assured 1.1.0 → 1.1.1

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.
@@ -7,13 +7,13 @@
7
7
  A tool for stubbing/spying on http(s) based services that your app under test interacts with. This is useful for blackbox/integration testing.
8
8
  There are three main use cases:
9
9
 
10
- * stubbing out external data sources with predefined data
10
+ * stub out external data sources with predefined data
11
11
  * verify requests to external services (aka spying)
12
12
  * simulate different behavior of external services using web UI; useful in development
13
13
 
14
14
  ## Usage
15
15
 
16
- You are going to need ruby >= 1.8.7.
16
+ You are going to need MRI ruby >= 1.8.7 on Linux/MacOS.
17
17
 
18
18
  Rest-assured requires a database to run. Either sqlite or mysql. So, make sure there is one and its backed with corresponding client gem:
19
19
 
@@ -72,7 +72,7 @@ RestAssured::Double.create(fullpath: '/products', content: 'this is content')
72
72
 
73
73
  Now GET `http://localhost:4578/products` will be returning `this is content`.
74
74
 
75
- You can also verify what requests happen on a double, or, if you like, spy on a it. Say this is a Given part of a test:
75
+ You can also verify what requests happen on a double (spy on it). Say this is a Given part of a test:
76
76
 
77
77
  ```ruby
78
78
  @double = RestAssured::Double.create(fullpath: '/products', verb: 'POST')
@@ -198,9 +198,14 @@ Here is the rest API for managing redirects:
198
198
 
199
199
  ## Changelog
200
200
 
201
+ #### 1.1.1 (01 Mar 2012)
202
+
203
+ * Add 'verb' to UI
204
+ * No more forked version of Server
205
+
201
206
  #### 1.1.0 (17 Feb 2012)
202
207
 
203
- * Redirects supports 'real' (without http redirect) rewrite to local double
208
+ * Redirects support 'real' (without http redirect) rewrite to local double
204
209
 
205
210
  #### 1.0.0 (14 Feb 2012)
206
211
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'rubygems'
2
3
  require "irb"
3
4
 
4
5
  $:.push File.expand_path('../../lib', __FILE__)
@@ -6,6 +7,6 @@ $:.push File.expand_path('../../lib', __FILE__)
6
7
  require 'rest-assured/config'
7
8
  RestAssured::Config.build :database => ( ENV['FRS_DB'] || File.expand_path('../../db/development.db', __FILE__) )
8
9
 
9
- require 'rest-assured'
10
+ require 'rest-assured/application'
10
11
 
11
12
  IRB.start(__FILE__)
@@ -71,7 +71,12 @@ end
71
71
 
72
72
  Given /^the following doubles exist:$/ do |doubles|
73
73
  doubles.hashes.each do |row|
74
- RestAssured::Models::Double.create(:fullpath => row['fullpath'], :description => row['description'], :content => row['content'])
74
+ RestAssured::Models::Double.create(
75
+ :fullpath => row['fullpath'],
76
+ :description => row['description'],
77
+ :content => row['content'],
78
+ :verb => row['verb']
79
+ )
75
80
  end
76
81
  end
77
82
 
@@ -83,6 +88,7 @@ Then /^I should see existing doubles:$/ do |doubles|
83
88
  doubles.hashes.each do |row|
84
89
  page.should have_content(row[:fullpath])
85
90
  page.should have_content(row[:description])
91
+ page.should have_content(row[:verb])
86
92
  end
87
93
  end
88
94
 
@@ -99,6 +105,7 @@ When /^I enter double details:$/ do |details|
99
105
 
100
106
  fill_in 'Request fullpath', :with => double['fullpath']
101
107
  fill_in 'Content', :with => double['content']
108
+ select double['verb'], :from => 'Verb'
102
109
  fill_in 'Description', :with => double['description']
103
110
  end
104
111
 
@@ -6,29 +6,29 @@ Feature: manage doubles via ui
6
6
 
7
7
  Scenario: view existing doubles
8
8
  Given the following doubles exist:
9
- | fullpath | description | content |
10
- | /url1/aaa | twitter | test content |
11
- | /url2/bbb | geo location | more content |
12
- | /u/b?c=1 | wikipedia | article |
9
+ | fullpath | description | content | verb |
10
+ | /url1/aaa | twitter | test content | GET |
11
+ | /url2/bbb | geo location | more content | POST |
12
+ | /u/b?c=1 | wikipedia | article | PUT |
13
13
  When I visit "doubles" page
14
14
  Then I should see that I am on "doubles" page
15
15
  And I should see existing doubles:
16
- | fullpath | description |
17
- | /url1/aaa | twitter |
18
- | /url2/bbb | geo location |
19
- | /u/b?c=1 | wikipedia |
16
+ | fullpath | description | verb |
17
+ | /url1/aaa | twitter | GET |
18
+ | /url2/bbb | geo location | POST |
19
+ | /u/b?c=1 | wikipedia | PUT |
20
20
 
21
21
  Scenario: add new double
22
22
  Given I am on "doubles" page
23
23
  When I choose to create a double
24
24
  And I enter double details:
25
- | fullpath | description | content |
26
- | /url2/bb?a=b5 | google api | test content |
25
+ | fullpath | description | content | verb |
26
+ | /url2/bb?a=b5 | google api | test content | POST |
27
27
  And I save it
28
28
  Then I should see "Double created"
29
29
  And I should see existing doubles:
30
- | fullpath | description |
31
- | /url2/bb?a=b5 | google api |
30
+ | fullpath | description | verb |
31
+ | /url2/bb?a=b5 | google api | POST |
32
32
 
33
33
  @javascript
34
34
  Scenario: choose active double
@@ -41,16 +41,16 @@ Feature: manage doubles via ui
41
41
 
42
42
  Scenario: edit double
43
43
  Given the following doubles exist:
44
- | fullpath | description | content |
45
- | /url1/aaa | twitter | test content |
44
+ | fullpath | description | content | verb |
45
+ | /url1/aaa | twitter | test content | POST |
46
46
  And I visit "doubles" page
47
47
  And I choose to edit double
48
48
  When I change "double" "description" to "google"
49
49
  And I save it
50
50
  Then I should see that I am on "doubles" page
51
51
  And I should see existing doubles:
52
- | fullpath | description |
53
- | /url1/aaa | google |
52
+ | fullpath | description | verb |
53
+ | /url1/aaa | google | POST |
54
54
 
55
55
  @javascript
56
56
  Scenario: delete double
@@ -1,29 +1,11 @@
1
- require 'rest-assured/utils/subprocess'
2
- require 'rest-assured/utils/drb_sniffer'
3
- require 'rest-assured/api/app_runner'
4
1
  require 'childprocess'
5
2
 
6
3
  module RestAssured
7
4
  class AppSession
8
- include Utils::DrbSniffer
9
-
10
5
  def initialize
11
- @child = if not running_in_spork? and Process.respond_to?(:fork)
12
- Utils::Subprocess.new do
13
- AppRunner.run!
14
- end
15
- else
16
- child = ChildProcess.build('rest-assured', *Config.to_cmdargs)
17
- child.io.inherit!
18
- child.start
19
- child
20
- end
21
- end
22
-
23
- def alive?
24
- @child.alive?
25
- rescue Errno::ECHILD
26
- false
6
+ @child = ChildProcess.build('rest-assured', *Config.to_cmdargs)
7
+ @child.io.inherit!
8
+ @child.start
27
9
  end
28
10
 
29
11
  def method_missing(*args)
@@ -3,6 +3,12 @@ require 'json'
3
3
  module RestAssured
4
4
  module DoubleRoutes
5
5
  def self.included(router)
6
+ router.helpers do
7
+ def verbs
8
+ RestAssured::Models::Double::VERBS
9
+ end
10
+ end
11
+
6
12
  router.get '/' do
7
13
  redirect to('/doubles')
8
14
  end
@@ -1,3 +1,3 @@
1
1
  module RestAssured
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -4,48 +4,22 @@ require File.expand_path('../../../lib/rest-assured/api/app_session', __FILE__)
4
4
 
5
5
  module RestAssured
6
6
  describe AppSession do
7
- context 'either without spork or outside prefork block' do
8
- before do
9
- AppSession.any_instance.stub(:running_in_spork? => false)
10
- end
7
+ it 'starts application in childprocess' do
8
+ cmdargs = %w{-d :memory: -p 6666}
9
+ Config.stub(:to_cmdargs => cmdargs)
11
10
 
12
- it 'start application in subprocess' do
13
- state = ''
14
- Utils::Subprocess.should_receive(:new) do |&block|
15
- state << 'called from block'
16
- block.call
17
- state = ''
18
- end
19
- AppRunner.should_receive(:run!) do
20
- state.should == 'called from block'
21
- end
11
+ ChildProcess.should_receive(:build).with('rest-assured', *cmdargs).and_return(child = mock(:io => mock))
22
12
 
23
- AppSession.new
13
+ state = ''
14
+ child.io.should_receive(:inherit!) do
15
+ state.should_not == 'started'
24
16
  end
25
- end
26
-
27
- context 'within spork prefork block' do
28
- before do
29
- AppSession.any_instance.stub(:running_in_spork? => true)
30
- end
31
-
32
- it 'starts application in childprocess' do
33
- cmdargs = %w{-d :memory: -p 6666}
34
- Config.stub(:to_cmdargs => cmdargs)
35
-
36
- ChildProcess.should_receive(:build).with('rest-assured', *cmdargs).and_return(child = mock(:io => mock))
37
-
38
- state = ''
39
- child.io.should_receive(:inherit!) do
40
- state.should_not == 'started'
41
- end
42
- child.should_receive(:start) do
43
- state << 'started'
44
- end
45
-
46
- AppSession.new
17
+ child.should_receive(:start) do
18
+ state << 'started'
47
19
  end
48
20
 
21
+ AppSession.new
49
22
  end
23
+
50
24
  end
51
25
  end
@@ -3,6 +3,13 @@ require File.expand_path('../../spec_helper', __FILE__)
3
3
 
4
4
  module RestAssured
5
5
  describe Double, 'ruby-api' => true do
6
+ before(:all) do
7
+ Server.start(DB_OPTS.merge(:port => 9877))
8
+ end
9
+ after(:all) do
10
+ Server.stop
11
+ end
12
+
6
13
  it { should be_kind_of ActiveResource::Base }
7
14
 
8
15
  it 'creates new double' do
@@ -3,15 +3,17 @@ require File.expand_path('../../../lib/rest-assured/api/server', __FILE__)
3
3
 
4
4
  module RestAssured
5
5
  describe Server do
6
- after do
6
+ around do |example|
7
+ Server.reset_instance
8
+ example.run
7
9
  Server.reset_instance
8
10
  end
9
11
 
10
12
  it 'khows when it is up' do
11
13
  AppSession.stub(:new).and_return(session = stub(:alive? => true).as_null_object)
12
14
  Utils::PortExplorer.stub(:port_free? => false)
13
- Server.start
14
15
 
16
+ Server.start
15
17
  Server.up?.should == true
16
18
  end
17
19
 
@@ -120,21 +122,18 @@ module RestAssured
120
122
  end
121
123
 
122
124
  it 'stops application subprocess when current process exits' do
123
- if not running_in_spork?
124
- res_file = Tempfile.new('res')
125
- AppSession.stub(:new).and_return(session = mock.as_null_object)
126
- session.stub(:stop) do
127
- res_file.write "stopped"
128
- res_file.rewind
129
- end
130
- fork do
131
- Server.start!
132
- end
133
- Process.wait
134
- res_file.read.should == 'stopped'
135
- else
136
- pending "Skipped: drb/spork breaks fork sandbox (at_exits are collected and fired all together on master process exit)"
125
+ res_file = Tempfile.new('res')
126
+ AppSession.stub(:new).and_return(session = mock.as_null_object)
127
+ session.stub(:alive?).and_return(false)
128
+ session.stub(:stop) do
129
+ res_file.write "stopped"
130
+ res_file.rewind
131
+ end
132
+ fork do
133
+ Server.start!
137
134
  end
135
+ Process.wait
136
+ res_file.read.should == 'stopped'
138
137
  end
139
138
  end
140
139
  end
@@ -6,6 +6,7 @@ module RestAssured
6
6
  {
7
7
  :fullpath => '/api/google?a=5',
8
8
  :content => 'some awesome content',
9
+ :description => 'awesome double',
9
10
  :verb => 'POST',
10
11
  :status => '201',
11
12
  :response_headers => { 'ACCEPT' => 'text/html' }
@@ -18,6 +19,7 @@ module RestAssured
18
19
  'double[content]' => test_double[:content],
19
20
  'double[verb]' => test_double[:verb],
20
21
  'double[status]' => test_double[:status],
22
+ 'double[description]' => test_double[:description],
21
23
  'double[response_headers]' => test_double[:response_headers]
22
24
  }
23
25
 
@@ -28,25 +30,33 @@ module RestAssured
28
30
  valid_params.except('double[fullpath]')
29
31
  end
30
32
 
31
- describe "through ui", :ui => true do
32
- it "shows doubles page by default" do
33
+ context "Web UI", :ui => true do
34
+ it "makes doubles index root page" do
33
35
  visit '/'
34
36
  current_path.should == '/doubles'
35
37
  end
36
38
 
37
- it "shows list of doubles" do
38
- f = Models::Double.create test_double
39
+ # this is tested in cucumber
40
+ it "renders doubles index" do
41
+ f = Models::Double.create test_double
42
+ f1 = Models::Double.create test_double.merge(:verb => 'GET')
39
43
 
40
44
  visit '/doubles'
41
45
 
42
46
  page.should have_content(f.fullpath)
47
+ page.should have_content(f.description)
48
+ page.should have_content(f.verb)
49
+ page.should have_content(f1.fullpath)
50
+ page.should have_content(f1.description)
51
+ page.should have_content(f1.verb)
43
52
  end
44
53
 
45
- it "shows form for creating new double" do
54
+ it "renders form for creating new double" do
46
55
  visit '/doubles/new'
47
56
 
48
57
  page.should have_css('#double_fullpath')
49
58
  page.should have_css('#double_content')
59
+ page.should have_css('#double_verb')
50
60
  page.should have_css('#double_description')
51
61
  end
52
62
 
@@ -68,7 +78,7 @@ module RestAssured
68
78
  last_response.body.should =~ /Crumps!.*Fullpath can't be blank/
69
79
  end
70
80
 
71
- it "brings up double edit form" do
81
+ it "renders double edit form" do
72
82
  f = Models::Double.create test_double
73
83
  visit "/doubles/#{f.id}/edit"
74
84
 
@@ -84,7 +94,11 @@ module RestAssured
84
94
 
85
95
  last_request.fullpath.should == '/doubles'
86
96
  last_response.body.should =~ /Double updated/
87
- f.reload.fullpath.should == '/some/other/api'
97
+ f.reload.fullpath.should == '/some/other/api'
98
+ f.content.should == test_double[:content]
99
+ f.verb.should == test_double[:verb]
100
+ f.status.to_s.should == test_double[:status]
101
+ f.response_headers.should == test_double[:response_headers]
88
102
  end
89
103
 
90
104
  it "chooses active double" do
@@ -109,7 +123,7 @@ module RestAssured
109
123
  end
110
124
  end
111
125
 
112
- describe "through REST api", :ui => false do
126
+ context "REST api", :ui => false do
113
127
  it "creates double" do
114
128
  post '/doubles', test_double
115
129
 
@@ -136,7 +150,7 @@ module RestAssured
136
150
  end
137
151
  end
138
152
 
139
- describe 'through REST (ActiveResource compatible) json api', :ui => false do
153
+ context 'REST (ActiveResource compatible) json api', :ui => false do
140
154
  it "creates double as AR resource" do
141
155
  post '/doubles.json', { :double => test_double }.to_json, 'CONTENT_TYPE' => 'Application/json'
142
156
 
@@ -24,7 +24,6 @@ Spork.prefork do
24
24
  require 'awesome_print'
25
25
  require File.expand_path('../support/custom_matchers', __FILE__)
26
26
  require File.expand_path('../support/reset-singleton', __FILE__)
27
- require 'rest-assured/utils/drb_sniffer'
28
27
 
29
28
  ENV['RACK_ENV'] = 'test'
30
29
 
@@ -40,7 +39,6 @@ Spork.prefork do
40
39
  c.include Capybara::DSL
41
40
  c.include Rack::Test::Methods
42
41
  c.include XhrHelpers
43
- c.include RestAssured::Utils::DrbSniffer
44
42
 
45
43
  c.before(:each) do
46
44
  DatabaseCleaner.start
@@ -65,17 +63,13 @@ Spork.prefork do
65
63
  end
66
64
  end
67
65
  require 'rest-assured/config'
68
- db_opts = { :dbuser => ENV['TRAVIS'] ? "''" : "root", :adapter => 'mysql' }
69
- RestAssured::Config.build(db_opts)
66
+ DB_OPTS = { :dbuser => ENV['TRAVIS'] ? "''" : "root", :adapter => 'mysql' }
67
+ RestAssured::Config.build(DB_OPTS)
70
68
 
71
69
  require 'rest-assured'
72
70
  require 'rest-assured/application'
73
71
  require 'shoulda-matchers'
74
72
 
75
- RestAssured::Server.start(db_opts.merge(:port => 9877))
76
- end
77
-
78
- Spork.each_run do
79
73
  Capybara.app = RestAssured::Application
80
74
 
81
75
  def app
@@ -84,3 +78,6 @@ Spork.each_run do
84
78
 
85
79
  DatabaseCleaner.strategy = :truncation
86
80
  end
81
+
82
+ Spork.each_run do
83
+ end
@@ -6,6 +6,12 @@
6
6
  %label{:for => 'double_content'} Content*
7
7
  %textarea.wide#double_content{:name => 'double[content]', :rows => 10}= @double.content
8
8
 
9
+ %p
10
+ %label{:for => 'double_verb'} Verb
11
+ %select#double_verb{:name => 'double[verb]'}
12
+ - verbs.each do |v|
13
+ %option{:name => v, :selected => (@double.verb == v)}= v
14
+
9
15
  %p
10
16
  %label{:for => 'double_description'} Description
11
17
  %textarea.wide#double_description{:name => 'double[description]', :rows => 3}= @double.description
@@ -4,6 +4,7 @@
4
4
  %thead
5
5
  %tr
6
6
  %th Request fullpath
7
+ %th Verb
7
8
  %th Description
8
9
  %th Active?
9
10
  %th &nbsp;
@@ -13,6 +14,7 @@
13
14
  %tr{:id => "double_row_#{f.id}"}
14
15
  - if i == 0
15
16
  %td{:rowspan => fs.size}= fullpath
17
+ %td= f.verb
16
18
  %td= f.description
17
19
  %td.label.text-center
18
20
  %input.active-double-toggle{:type => 'radio', :name => fullpath, :checked => f.active, :data => { :double_id => f.id }}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-assured
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000 Z
12
+ date: 2012-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &2168491020 !ruby/object:Gem::Requirement
16
+ requirement: &2157317900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2168491020
24
+ version_requirements: *2157317900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: childprocess
27
- requirement: &2168528060 !ruby/object:Gem::Requirement
27
+ requirement: &2157317260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.3.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2168528060
35
+ version_requirements: *2157317260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra-flash
38
- requirement: &2168523560 !ruby/object:Gem::Requirement
38
+ requirement: &2157316120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2168523560
46
+ version_requirements: *2157316120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: haml
49
- requirement: &2168565440 !ruby/object:Gem::Requirement
49
+ requirement: &2157338020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.1.3
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2168565440
57
+ version_requirements: *2157338020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activerecord
60
- requirement: &2168564340 !ruby/object:Gem::Requirement
60
+ requirement: &2157335780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 3.1.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2168564340
68
+ version_requirements: *2157335780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activeresource
71
- requirement: &2168563340 !ruby/object:Gem::Requirement
71
+ requirement: &2157332420 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 3.1.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2168563340
79
+ version_requirements: *2157332420
80
80
  description:
81
81
  email:
82
82
  - artem.avetisyan@bbc.co.uk
@@ -128,7 +128,6 @@ files:
128
128
  - features/web_ui/redirects.feature
129
129
  - lib/rest-assured.rb
130
130
  - lib/rest-assured/api.rb
131
- - lib/rest-assured/api/app_runner.rb
132
131
  - lib/rest-assured/api/app_session.rb
133
132
  - lib/rest-assured/api/resources.rb
134
133
  - lib/rest-assured/api/server.rb
@@ -140,9 +139,7 @@ files:
140
139
  - lib/rest-assured/routes/double.rb
141
140
  - lib/rest-assured/routes/redirect.rb
142
141
  - lib/rest-assured/routes/response.rb
143
- - lib/rest-assured/utils/drb_sniffer.rb
144
142
  - lib/rest-assured/utils/port_explorer.rb
145
- - lib/rest-assured/utils/subprocess.rb
146
143
  - lib/rest-assured/version.rb
147
144
  - lib/sinatra/handler_options_patch.rb
148
145
  - lib/sinatra/partials.rb
@@ -164,7 +161,6 @@ files:
164
161
  - public/javascript/application.js
165
162
  - public/javascript/jquery.jgrowl_minimized.js
166
163
  - rest-assured.gemspec
167
- - spec/api/app_runner_spec.rb
168
164
  - spec/api/app_session_spec.rb
169
165
  - spec/api/resource_double_spec.rb
170
166
  - spec/api/server_spec.rb
@@ -177,7 +173,6 @@ files:
177
173
  - spec/models/request_spec.rb
178
174
  - spec/port_explorer_spec.rb
179
175
  - spec/spec_helper.rb
180
- - spec/subprocess_spec.rb
181
176
  - spec/support/custom_matchers.rb
182
177
  - spec/support/reset-singleton.rb
183
178
  - ssl/localhost.crt
@@ -211,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
206
  version: '0'
212
207
  segments:
213
208
  - 0
214
- hash: 1944321672567783063
209
+ hash: -2495133129201984062
215
210
  requirements: []
216
211
  rubyforge_project: rest-assured
217
212
  rubygems_version: 1.8.10
@@ -237,7 +232,6 @@ test_files:
237
232
  - features/support/world_helpers.rb
238
233
  - features/web_ui/doubles.feature
239
234
  - features/web_ui/redirects.feature
240
- - spec/api/app_runner_spec.rb
241
235
  - spec/api/app_session_spec.rb
242
236
  - spec/api/resource_double_spec.rb
243
237
  - spec/api/server_spec.rb
@@ -250,6 +244,5 @@ test_files:
250
244
  - spec/models/request_spec.rb
251
245
  - spec/port_explorer_spec.rb
252
246
  - spec/spec_helper.rb
253
- - spec/subprocess_spec.rb
254
247
  - spec/support/custom_matchers.rb
255
248
  - spec/support/reset-singleton.rb
@@ -1,18 +0,0 @@
1
- require 'singleton'
2
-
3
- module RestAssured
4
- class AppRunner
5
- include Singleton
6
-
7
- def run!
8
- unless Kernel.require 'rest-assured/application'
9
- RestAssured::Application.send(:include, Config)
10
- end
11
- RestAssured::Application.run!
12
- end
13
-
14
- def self.method_missing(*args)
15
- instance.send(*args)
16
- end
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- require 'drb'
2
-
3
- module RestAssured
4
- module Utils
5
- module DrbSniffer
6
- def running_in_spork?
7
- defined?(Spork) && Spork.using_spork?
8
- end
9
- end
10
- end
11
- end
@@ -1,41 +0,0 @@
1
- module RestAssured
2
- module Utils
3
- class Subprocess
4
- attr_reader :pid
5
-
6
- def initialize
7
- @pid = Kernel.fork do
8
- trap('USR1') do
9
- Process.kill('TERM', Process.pid) # unlike 'exit' this one is NOT being intercepted by Webrick
10
- end
11
-
12
- at_exit { exit! }
13
-
14
- begin
15
- yield
16
- rescue => e
17
- if defined?(EventMachine) && e.is_a?(EventMachine::ConnectionNotBound)
18
- retry
19
- end
20
- puts "#{self} has raised #{e.inspect}:"
21
- puts e.backtrace.join("\n")
22
- end
23
- end
24
-
25
- Process.detach(@pid)
26
- at_exit { stop }
27
- end
28
-
29
- def alive?
30
- Process.kill(0, @pid)
31
- true
32
- rescue Errno::ESRCH
33
- false
34
- end
35
-
36
- def stop
37
- Process.kill('USR1', @pid) rescue Errno::ESRCH # no such process
38
- end
39
- end
40
- end
41
- end
@@ -1,27 +0,0 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../../../lib/rest-assured/api/app_runner', __FILE__)
3
-
4
- module RestAssured
5
- describe AppRunner do
6
- before do
7
- Application.stub(:run!)
8
- Config.stub(:included)
9
- end
10
-
11
- it 'requires Application' do
12
- Kernel.should_receive(:require).with('rest-assured/application').and_return(true)
13
- AppRunner.run!
14
- end
15
- it 'reloads config if Application has already been loaded' do
16
- Kernel.stub(:require).and_return(false)
17
-
18
- Application.should_receive(:send).with(:include, Config)
19
- AppRunner.run!
20
- end
21
- it 'runs Application' do
22
- Application.should_receive(:run!)
23
- AppRunner.run!
24
- end
25
- end
26
- end
27
-
@@ -1,114 +0,0 @@
1
- require 'tempfile'
2
- require File.expand_path('../spec_helper', __FILE__)
3
- require File.expand_path('../../lib/rest-assured/utils/subprocess', __FILE__)
4
-
5
- module RestAssured::Utils
6
- describe Subprocess do
7
-
8
- it 'forks passed block' do
9
- ppid_file = Tempfile.new('ppidfile')
10
- pid_file = Tempfile.new('pidfile')
11
-
12
- fork do
13
- pid_file.write(Process.pid)
14
- pid_file.rewind
15
- at_exit { exit! }
16
- Subprocess.new do
17
- ppid_file.write(Process.ppid)
18
- ppid_file.rewind
19
- sleep 2
20
- end
21
- sleep 0.5
22
- end
23
- Process.wait
24
- ppid_file.read.should == pid_file.read
25
- end
26
-
27
- it 'ensures no zombies' do
28
- Kernel.stub(:fork).and_return(pid = 1)
29
- Process.should_receive(:detach).with(pid)
30
-
31
- Subprocess.new {1}
32
- end
33
-
34
- it 'knows when it is running' do
35
- res_file = Tempfile.new('res')
36
- fork do
37
- at_exit { exit! }
38
- child = Subprocess.new { sleep 0.5 }
39
- res_file.write(child.alive?)
40
- res_file.rewind
41
- end
42
- Process.wait
43
- res_file.read.should == 'true'
44
- end
45
-
46
- context 'shuts down child process' do
47
- let(:child_pid) do
48
- Tempfile.new('child_pid')
49
- end
50
-
51
- let(:child_alive?) do
52
- begin
53
- Process.kill(0, child_pid.read.to_i)
54
- true
55
- rescue Errno::ESRCH
56
- false
57
- end
58
- end
59
-
60
- it 'when stopped' do
61
- res_file = Tempfile.new('res')
62
- fork do
63
- at_exit { exit! }
64
- child = Subprocess.new { sleep 2 }
65
- child.stop
66
- sleep 1
67
- res_file.write(child.alive?)
68
- res_file.rewind
69
- end
70
- Process.wait
71
- sleep 0.5
72
- res_file.read.should == 'false'
73
- end
74
-
75
- it 'when exits normally' do
76
- if not running_in_spork?
77
- child_pid # Magic touch. Literally. Else Tempfile gets created in fork and that messes things up
78
-
79
- fork do
80
- at_exit { exit! }
81
- child = Subprocess.new { sleep 2 }
82
- child_pid.write(child.pid)
83
- child_pid.rewind
84
- end
85
-
86
- sleep 0.5
87
- child_alive?.should == false
88
- else
89
- pending "Skipped: drb/spork breaks fork sandbox (at_exits are collected and fired all together on master process exit)"
90
- end
91
- end
92
-
93
- it 'when killed violently' do
94
- if not running_in_spork?
95
- child_pid
96
-
97
- fork do
98
- at_exit { exit! }
99
- child = Subprocess.new { sleep 2 }
100
- child_pid.write(child.pid)
101
- child_pid.rewind
102
-
103
- Process.kill('TERM', Process.pid)
104
- end
105
-
106
- sleep 0.5
107
- child_alive?.should == false
108
- else
109
- pending "Skipped: drb/spork breaks fork sandbox (at_exits are collected and fired all together on master process exit)"
110
- end
111
- end
112
- end
113
- end
114
- end