fake_sqs 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0181bd620b8a9e315b0e9eed4411724da6e94014
4
- data.tar.gz: 189776545fdd3f8435781e95a9f045b1382ed819
3
+ metadata.gz: 5ffdf71e44c5de564702286a5fb677693ffa8098
4
+ data.tar.gz: e47abd738c5707b3fef71b580e847b08ea26ffa2
5
5
  SHA512:
6
- metadata.gz: fd85ec3adec752dcfd5be80763880f611ae9709e5275d8d4598b126fa4338a8d10c4b8e64f44754088181f039d01c8f2aebb80a4c4fcf9897a50c95c5ccdc080
7
- data.tar.gz: 2a12038c1de6692a6fe778bea212cc65d9f9972a64fd494b757169091902532d1fe46832d118b70321ec7f4fd32156b0220a0c17daa7da2d5471563a610cc528
6
+ metadata.gz: 56db094e2373419a92f3d3671ed30bb10ebd56974f7bbf7e00befe8f84762d0cb0c2957d6649e21ac2823368ed6ecbcd9bfc93d589c10078de34d120234cccc7
7
+ data.tar.gz: ef9b9117d913f6f813b98621143f6e3dfa3fb5623d765a0bf1590b00eaea3f553bd14315a90b1949901797e609964a6d90aefb33696e951c53a180d5e755d008
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format progress
2
2
  --color
3
+ --order random
data/README.md CHANGED
@@ -85,5 +85,65 @@ $ curl -X PUT http://localhost:4568/
85
85
  ```
86
86
 
87
87
 
88
+ ### Test Integration
89
+
90
+ When making integration tests for your app, you can easily include Fake SQS.
91
+
92
+ Here are the methods you need to run FakeSQS programmatically.
93
+
94
+ ``` ruby
95
+ require "fake_sqs/test_integration"
96
+
97
+ # globally, before the test suite starts:
98
+ AWS.config(
99
+ use_ssl: false,
100
+ sqs_endpoint: "localhost",
101
+ sqs_port: 4568,
102
+ access_key_id: "fake access key",
103
+ secret_access_key: "fake secret key",
104
+ )
105
+ fake_sqs = FakeSQS::TestIntegration.new
106
+
107
+ # before each test that requires SQS:
108
+ fake_sqs.start
109
+
110
+ # at the end of the suite:
111
+ at_exit {
112
+ fake_sqs.stop
113
+ }
114
+ ```
115
+
116
+ By starting it like this it will start when needed, and reset between each test.
117
+
118
+ Here's an example for RSpec to put in `spec/spec_helper.rb`:
119
+
120
+ ``` ruby
121
+ AWS.config(
122
+ use_ssl: false,
123
+ sqs_endpoint: "localhost",
124
+ sqs_port: 4568,
125
+ access_key_id: "fake access key",
126
+ secret_access_key: "fake secret key",
127
+ )
128
+
129
+ RSpec.configure do |config|
130
+ config.treat_symbols_as_metadata_keys_with_true_values = true
131
+ config.before(:suite) { $fake_sqs = FakeSQS::TestIntegration.new }
132
+ config.before(:each, :sqs) { $fake_sqs.start }
133
+ config.after(:suite) { $fake_sqs.stop }
134
+ end
135
+ ```
136
+
137
+ Now you can use the `:sqs metadata to enable SQS integration:
138
+
139
+ ``` ruby
140
+ describe "something with sqs", :sqs do
141
+ it "should work" do
142
+ queue = AWS::SQS.new.queues.create("my-queue")
143
+ end
144
+ end
145
+ ```
146
+
147
+
88
148
  [fake_dynamo]: https://github.com/ananthakumaran/fake_dynamo
89
149
  [aws-sdk]: https://github.com/amazonwebservices/aws-sdk-for-ruby
data/fake_sqs.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+ gem.license = "MIT"
19
20
 
20
21
  gem.add_dependency "sinatra"
21
22
  gem.add_dependency "builder"
@@ -0,0 +1,94 @@
1
+ require "net/http"
2
+
3
+ module FakeSQS
4
+ class TestIntegration
5
+
6
+ attr_reader :options
7
+
8
+ def initialize(options = {})
9
+ @options = options
10
+ end
11
+
12
+ def host
13
+ option :sqs_endpoint
14
+ end
15
+
16
+ def port
17
+ option :sqs_port
18
+ end
19
+
20
+ def start
21
+ start! unless up?
22
+ reset
23
+ end
24
+
25
+ def start!
26
+ @pid = Process.spawn(binfile, "-p", port.to_s, :out => out, :err => out)
27
+ wait_until_up
28
+ end
29
+
30
+ def stop
31
+ if @pid
32
+ Process.kill("INT", @pid)
33
+ Process.waitpid(@pid)
34
+ @pid = nil
35
+ else
36
+ $stderr.puts "FakeSQS is not running"
37
+ end
38
+ end
39
+
40
+ def reset
41
+ connection.delete("/")
42
+ end
43
+
44
+ def expire
45
+ connection.put("/", "")
46
+ end
47
+
48
+ def url
49
+ "http://#{host}:#{port}"
50
+ end
51
+
52
+ def up?
53
+ @pid && connection.get("/").code.to_s == "200"
54
+ rescue Errno::ECONNREFUSED
55
+ false
56
+ end
57
+
58
+ private
59
+
60
+ def option(key)
61
+ options.fetch(key) { AWS.config.public_send(key) }
62
+ end
63
+
64
+
65
+ def wait_until_up(deadline = Time.now + 2)
66
+ fail "FakeSQS didn't start in time" if Time.now > deadline
67
+ unless up?
68
+ sleep 0.01
69
+ wait_until_up(deadline)
70
+ end
71
+ end
72
+
73
+ def binfile
74
+ File.expand_path("../../../bin/fake_sqs", __FILE__)
75
+ end
76
+
77
+ def out
78
+ if debug?
79
+ :out
80
+ else
81
+ "/dev/null"
82
+ end
83
+ end
84
+
85
+ def connection
86
+ @connection ||= Net::HTTP.new(host, port)
87
+ end
88
+
89
+ def debug?
90
+ ENV["DEBUG"].to_s == "true"
91
+ end
92
+
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module FakeSQS
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,6 +1,6 @@
1
- require 'support/aws'
1
+ require "spec_helper"
2
2
 
3
- describe "Actions for Messages", :acceptance do
3
+ describe "Actions for Messages", :sqs do
4
4
 
5
5
  before do
6
6
  sqs.queues.create("test")
@@ -56,4 +56,8 @@ describe "Actions for Messages", :acceptance do
56
56
  messages.map(&:body).should match_array bodies
57
57
  end
58
58
 
59
+ def let_messages_in_flight_expire
60
+ $fake_sqs.expire
61
+ end
62
+
59
63
  end
@@ -1,6 +1,6 @@
1
- require 'support/aws'
1
+ require "spec_helper"
2
2
 
3
- describe "Actions for Queues", :acceptance do
3
+ describe "Actions for Queues", :sqs do
4
4
 
5
5
  let(:sqs) { AWS::SQS.new }
6
6
 
@@ -18,7 +18,7 @@ describe "Actions for Queues", :acceptance do
18
18
  specify "ListQueues" do
19
19
  sqs.queues.create("test-list-1")
20
20
  sqs.queues.create("test-list-2")
21
- queues = sqs.queues.map(&:url).should eq [
21
+ sqs.queues.map(&:url).should eq [
22
22
  "http://0.0.0.0:4568/test-list-1",
23
23
  "http://0.0.0.0:4568/test-list-2"
24
24
  ]
@@ -28,9 +28,9 @@ describe "Actions for Queues", :acceptance do
28
28
  sqs.queues.create("test-list-1")
29
29
  sqs.queues.create("test-list-2")
30
30
  sqs.queues.create("other-list-3")
31
- queues = sqs.queues.with_prefix("test").map(&:url).should eq [
31
+ sqs.queues.with_prefix("test").map(&:url).should eq [
32
32
  "http://0.0.0.0:4568/test-list-1",
33
- "http://0.0.0.0:4568/test-list-2"
33
+ "http://0.0.0.0:4568/test-list-2",
34
34
  ]
35
35
  end
36
36
 
@@ -0,0 +1,21 @@
1
+ require "aws-sdk"
2
+ require "fake_sqs/test_integration"
3
+
4
+ AWS.config(
5
+ :use_ssl => false,
6
+ :sqs_endpoint => "localhost",
7
+ :sqs_port => 4568,
8
+ :access_key_id => "fake access key",
9
+ :secret_access_key => "fake secret key",
10
+ )
11
+
12
+ $fake_sqs = FakeSQS::TestIntegration.new
13
+
14
+ RSpec.configure do |config|
15
+
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.before(:suite) { $fake_sqs = FakeSQS::TestIntegration.new }
18
+ config.before(:each, :sqs) { $fake_sqs.start }
19
+ config.after(:suite) { $fake_sqs.stop }
20
+
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_sqs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - iain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-27 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -174,11 +174,12 @@ files:
174
174
  - lib/fake_sqs/responder.rb
175
175
  - lib/fake_sqs/server.rb
176
176
  - lib/fake_sqs/show_output.rb
177
+ - lib/fake_sqs/test_integration.rb
177
178
  - lib/fake_sqs/version.rb
178
179
  - lib/fake_sqs/web_interface.rb
179
180
  - spec/acceptance/message_actions_spec.rb
180
181
  - spec/acceptance/queue_actions_spec.rb
181
- - spec/support/aws.rb
182
+ - spec/spec_helper.rb
182
183
  - spec/unit/api_spec.rb
183
184
  - spec/unit/catch_errors_spec.rb
184
185
  - spec/unit/error_response_spec.rb
@@ -189,7 +190,8 @@ files:
189
190
  - spec/unit/responder_spec.rb
190
191
  - spec/unit/show_output_spec.rb
191
192
  homepage: https://github.com/iain/fake_sqs
192
- licenses: []
193
+ licenses:
194
+ - MIT
193
195
  metadata: {}
194
196
  post_install_message:
195
197
  rdoc_options: []
@@ -214,7 +216,7 @@ summary: Provides a fake SQS server that you can run locally to test against
214
216
  test_files:
215
217
  - spec/acceptance/message_actions_spec.rb
216
218
  - spec/acceptance/queue_actions_spec.rb
217
- - spec/support/aws.rb
219
+ - spec/spec_helper.rb
218
220
  - spec/unit/api_spec.rb
219
221
  - spec/unit/catch_errors_spec.rb
220
222
  - spec/unit/error_response_spec.rb
data/spec/support/aws.rb DELETED
@@ -1,95 +0,0 @@
1
- require 'aws-sdk'
2
- require 'fake_sqs'
3
- require 'faraday'
4
- require 'uri'
5
- require 'thin'
6
-
7
- Thread.abort_on_exception = true
8
-
9
- ENV['RACK_ENV'] = 'test'
10
-
11
- Thin::Logging.silent = true
12
-
13
- class FakeServer
14
-
15
- attr_reader :url
16
-
17
- def initialize(url = "http://0.0.0.0:4568")
18
- @url = url
19
- end
20
-
21
- def uri
22
- @uri ||= URI.parse(url)
23
- end
24
-
25
- def port
26
- uri.port
27
- end
28
-
29
- def host
30
- uri.host
31
- end
32
-
33
- def ssl?
34
- uri.scheme == "https"
35
- end
36
-
37
- def start
38
- return if @started
39
- @started = true
40
- @fake_sqs_thread = Thread.new {
41
- load File.expand_path('../../../bin/fake_sqs', __FILE__)
42
- }
43
- wait_until_up
44
- end
45
-
46
- def stop
47
- @fake_sqs_thread.kill
48
- end
49
-
50
- def reset
51
- Faraday.delete(url)
52
- end
53
-
54
- def expire_messages_in_flight
55
- Faraday.put(url)
56
- end
57
-
58
- def wait_until_up(tries = 0)
59
- fail "Server didn't start in time" if tries > 200
60
- response = Faraday.get(url)
61
- if response.status != 200
62
- wait_until_up(tries + 1)
63
- end
64
- rescue Faraday::Error::ConnectionFailed
65
- wait_until_up(tries + 1)
66
- end
67
-
68
- end
69
-
70
- $fake_server = FakeServer.new
71
-
72
- module FakeServerHelper
73
-
74
- def let_messages_in_flight_expire
75
- $fake_server.expire_messages_in_flight
76
- end
77
-
78
- end
79
-
80
- AWS.config(
81
- :use_ssl => $fake_server.ssl?,
82
- :sqs_endpoint => $fake_server.host,
83
- :sqs_port => $fake_server.port,
84
- :access_key_id => "access key id",
85
- :secret_access_key => "secret access key"
86
- )
87
-
88
-
89
- RSpec.configure do |config|
90
- config.treat_symbols_as_metadata_keys_with_true_values = true
91
- config.before(:suite) { $fake_server.start }
92
- config.after(:suite) { $fake_server.stop }
93
- config.before(:each, :acceptance) { $fake_server.reset }
94
- config.include FakeServerHelper
95
- end