fake_sqs 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04b7e156149ca16643c8fde1933bca20aea7434b
4
- data.tar.gz: be9d4103aa2987ddbb43839c15f3ef85955b8e18
3
+ metadata.gz: 5160588ed7c7aea6fa2b5bd7d724b188068eec6e
4
+ data.tar.gz: 39d0c2eda9bb4c9f7182e4de0ca66e906fd4aa42
5
5
  SHA512:
6
- metadata.gz: 4ffeacbcc77e857c5c125d90c3eaafdb4bbc068c4f8fc8b11d705d4f3c0e0fa26ef82bd5427cd882ef02e317375b8f35bcdb8399aa3c8bd88aa27763c28e7a89
7
- data.tar.gz: 2a8dc5a14fbb7317e7ae6d44e9f79983568a3d204b74359d0cc2932dadd283b9a5ee79008ecb5dc1e649b596afc5ca4d658455cb6e508a420142a706a44e0983
6
+ metadata.gz: 8a560e5b111974eb836fd19f73d53615e5701e73000ebfbef51952705555b67e11c001caaa46057174482732463ac11d44ff82c01189023105cff5fe2dee491f
7
+ data.tar.gz: c921ba2c535b4897c777644bf5c96108a6a94ec6a09382a93fcb1b9eba61e99a3d6a348367dd6a18fd2dd31be7af2f92c8e79cc371f2808605a99d4a26da4d1d
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
3
  --order random
4
+ --require spec_helper
data/fake_sqs.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
 
24
24
  gem.add_development_dependency "rspec"
25
25
  gem.add_development_dependency "rake"
26
- gem.add_development_dependency "aws-sdk"
26
+ gem.add_development_dependency "aws-sdk", "~> 2.0"
27
27
  gem.add_development_dependency "faraday"
28
28
  gem.add_development_dependency "thin"
29
29
  gem.add_development_dependency "verbose_hash_fetch"
data/lib/fake_sqs.rb CHANGED
@@ -20,8 +20,10 @@ module FakeSQS
20
20
  app = FakeSQS::WebInterface
21
21
 
22
22
  if (log = options[:log])
23
- $stdout.reopen(log, "w:utf-8")
24
- $stderr.reopen(log, "w:utf-8")
23
+ file = File.new(log, "a+")
24
+ file.sync = true
25
+ app.use Rack::CommonLogger, file
26
+ app.set :log_file, file
25
27
  app.enable :logging
26
28
  end
27
29
 
@@ -1,4 +1,5 @@
1
- require 'rack/request'
1
+ require 'rack'
2
+ require 'yaml'
2
3
 
3
4
  module FakeSQS
4
5
  class ShowOutput
@@ -12,7 +13,7 @@ module FakeSQS
12
13
  result = @app.call(env)
13
14
  puts request.params.to_yaml
14
15
  puts
15
- puts *result.last
16
+ puts(*result.last)
16
17
  result
17
18
  end
18
19
 
@@ -50,6 +50,10 @@ module FakeSQS
50
50
  "http://#{host}:#{port}"
51
51
  end
52
52
 
53
+ def uri
54
+ URI(url)
55
+ end
56
+
53
57
  def up?
54
58
  @pid && connection.get("/").code.to_s == "200"
55
59
  rescue Errno::ECONNREFUSED
@@ -59,7 +63,7 @@ module FakeSQS
59
63
  private
60
64
 
61
65
  def option(key)
62
- options.fetch(key) { AWS.config.public_send(key) }
66
+ options.fetch(key)
63
67
  end
64
68
 
65
69
  def database
@@ -1,3 +1,3 @@
1
1
  module FakeSQS
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,99 +1,211 @@
1
- require "spec_helper"
1
+ require "integration_spec_helper"
2
+ require "securerandom"
2
3
 
3
- describe "Actions for Messages", :sqs do
4
+ RSpec.describe "Actions for Messages", :sqs do
5
+
6
+ QUEUE_NAME = "test"
4
7
 
5
8
  before do
6
- sqs.queues.create("test")
9
+ sqs.config.endpoint = $fake_sqs.uri
10
+ sqs.create_queue(queue_name: QUEUE_NAME)
7
11
  end
8
12
 
9
- let(:sqs) { AWS::SQS.new }
10
- let(:queue) { sqs.queues.named("test") }
13
+ let(:sqs) { Aws::SQS::Client.new }
14
+
15
+ let(:queue_url) { sqs.get_queue_url(queue_name: QUEUE_NAME).queue_url }
11
16
 
12
17
  specify "SendMessage" do
13
18
  msg = "this is my message"
14
- result = queue.send_message(msg)
15
- result.md5.should eq Digest::MD5.hexdigest(msg)
19
+
20
+ result = sqs.send_message(
21
+ queue_url: queue_url,
22
+ message_body: msg,
23
+ )
24
+
25
+ expect(result.md5_of_message_body).to eq Digest::MD5.hexdigest(msg)
26
+ expect(result.message_id.size).to eq 36
16
27
  end
17
28
 
18
29
  specify "ReceiveMessage" do
19
30
  body = "test 123"
20
- queue.send_message(body)
21
- message = queue.receive_message
22
- message.body.should eq body
31
+
32
+ sqs.send_message(
33
+ queue_url: queue_url,
34
+ message_body: body
35
+ )
36
+
37
+ response = sqs.receive_message(
38
+ queue_url: queue_url,
39
+ )
40
+
41
+ expect(response.messages.size).to eq 1
42
+
43
+ expect(response.messages.first.body).to eq body
23
44
  end
24
45
 
25
46
  specify "DeleteMessage" do
26
- queue.send_message("test")
47
+ sqs.send_message(
48
+ queue_url: queue_url,
49
+ message_body: "test",
50
+ )
27
51
 
28
- message1 = queue.receive_message
29
- message1.delete
52
+ message1 = sqs.receive_message(
53
+ queue_url: queue_url,
54
+ ).messages.first
55
+
56
+ sqs.delete_message(
57
+ queue_url: queue_url,
58
+ receipt_handle: message1.receipt_handle,
59
+ )
30
60
 
31
61
  let_messages_in_flight_expire
32
62
 
33
- message2 = queue.receive_message
34
- message2.should be_nil
63
+ response = sqs.receive_message(
64
+ queue_url: queue_url,
65
+ )
66
+ expect(response.messages.size).to eq 0
35
67
  end
36
68
 
37
69
  specify "DeleteMessageBatch" do
38
- queue.send_message("test1")
39
- queue.send_message("test2")
40
-
41
- message1 = queue.receive_message
42
- message2 = queue.receive_message
43
- queue.batch_delete(message1, message2)
70
+ sqs.send_message(
71
+ queue_url: queue_url,
72
+ message_body: "test1"
73
+ )
74
+ sqs.send_message(
75
+ queue_url: queue_url,
76
+ message_body: "test2"
77
+ )
78
+
79
+ messages_response = sqs.receive_message(
80
+ queue_url: queue_url,
81
+ max_number_of_messages: 2,
82
+ )
83
+
84
+ entries = messages_response.messages.map { |msg|
85
+ {
86
+ id: SecureRandom.uuid,
87
+ receipt_handle: msg.receipt_handle,
88
+ }
89
+ }
90
+
91
+ sqs.delete_message_batch(
92
+ queue_url: queue_url,
93
+ entries: entries,
94
+ )
44
95
 
45
96
  let_messages_in_flight_expire
46
97
 
47
- message3 = queue.receive_message
48
- message3.should be_nil
98
+ response = sqs.receive_message(
99
+ queue_url: queue_url,
100
+ )
101
+ expect(response.messages.size).to eq 0
49
102
  end
50
103
 
51
104
  specify "SendMessageBatch" do
52
105
  bodies = %w(a b c)
53
- queue.batch_send(*bodies)
54
106
 
55
- messages = queue.receive_message(:limit => 10)
56
- messages.map(&:body).should match_array bodies
107
+ sqs.send_message_batch(
108
+ queue_url: queue_url,
109
+ entries: bodies.map { |bd|
110
+ {
111
+ id: SecureRandom.uuid,
112
+ message_body: bd,
113
+ }
114
+ }
115
+ )
116
+
117
+ messages_response = sqs.receive_message(
118
+ queue_url: queue_url,
119
+ max_number_of_messages: 3,
120
+ )
121
+
122
+ expect(messages_response.messages.map(&:body)).to match_array bodies
57
123
  end
58
124
 
59
125
  specify "set message timeout to 0" do
60
126
  body = 'some-sample-message'
61
- queue.send_message(body)
62
- message = queue.receive_message
63
- message.body.should == body
64
- message.visibility_timeout = 0
65
127
 
66
- same_message = queue.receive_message
67
- same_message.body.should == body
128
+ sqs.send_message(
129
+ queue_url: queue_url,
130
+ message_body: body,
131
+ )
132
+
133
+ message = sqs.receive_message(
134
+ queue_url: queue_url,
135
+ ).messages.first
136
+
137
+ expect(message.body).to eq body
138
+
139
+ sqs.change_message_visibility(
140
+ queue_url: queue_url,
141
+ receipt_handle: message.receipt_handle,
142
+ visibility_timeout: 0
143
+ )
144
+
145
+ same_message = sqs.receive_message(
146
+ queue_url: queue_url,
147
+ ).messages.first
148
+ expect(same_message.body).to eq body
68
149
  end
69
150
 
70
151
  specify 'set message timeout and wait for message to come' do
71
152
 
72
153
  body = 'some-sample-message'
73
- queue.send_message(body)
74
- message = queue.receive_message
75
- message.body.should == body
76
- message.visibility_timeout = 3
77
-
78
- nothing = queue.receive_message
79
- nothing.should be_nil
80
-
81
- sleep(10)
82
154
 
83
- same_message = queue.receive_message
84
- same_message.body.should == body
155
+ sqs.send_message(
156
+ queue_url: queue_url,
157
+ message_body: body,
158
+ )
159
+
160
+ message = sqs.receive_message(
161
+ queue_url: queue_url,
162
+ ).messages.first
163
+ expect(message.body).to eq body
164
+
165
+ sqs.change_message_visibility(
166
+ queue_url: queue_url,
167
+ receipt_handle: message.receipt_handle,
168
+ visibility_timeout: 2
169
+ )
170
+
171
+ nothing = sqs.receive_message(
172
+ queue_url: queue_url,
173
+ )
174
+ expect(nothing.messages.size).to eq 0
175
+
176
+ sleep(5)
177
+
178
+ same_message = sqs.receive_message(
179
+ queue_url: queue_url,
180
+ ).messages.first
181
+ expect(same_message.body).to eq body
85
182
  end
86
183
 
87
184
  specify 'should fail if trying to update the visibility_timeout for a message that is not in flight' do
88
185
  body = 'some-sample-message'
89
- queue.send_message(body)
90
- message = queue.receive_message
91
- message.body.should == body
92
- message.visibility_timeout = 0
93
-
94
- expect do
95
- message.visibility_timeout = 30
96
- end.to raise_error(AWS::SQS::Errors::MessageNotInflight)
186
+ sqs.send_message(
187
+ queue_url: queue_url,
188
+ message_body: body,
189
+ )
190
+
191
+ message = sqs.receive_message(
192
+ queue_url: queue_url,
193
+ ).messages.first
194
+ expect(message.body).to eq body
195
+
196
+ sqs.change_message_visibility(
197
+ queue_url: queue_url,
198
+ receipt_handle: message.receipt_handle,
199
+ visibility_timeout: 0
200
+ )
201
+
202
+ expect {
203
+ sqs.change_message_visibility(
204
+ queue_url: queue_url,
205
+ receipt_handle: message.receipt_handle,
206
+ visibility_timeout: 30
207
+ )
208
+ }.to raise_error(Aws::SQS::Errors::MessageNotInflight)
97
209
  end
98
210
 
99
211
  def let_messages_in_flight_expire
@@ -1,61 +1,67 @@
1
- require "spec_helper"
1
+ require "integration_spec_helper"
2
+ require "pry"
2
3
 
3
- describe "Actions for Queues", :sqs do
4
+ RSpec.describe "Actions for Queues", :sqs do
4
5
 
5
- let(:sqs) { AWS::SQS.new }
6
+ let(:sqs) { Aws::SQS::Client.new }
7
+ before do
8
+ sqs.config.endpoint = $fake_sqs.uri
9
+ end
6
10
 
7
11
  specify "CreateQueue" do
8
- queue = sqs.queues.create("test-create-queue")
9
- queue.url.should eq "http://0.0.0.0:4568/test-create-queue"
10
- queue.arn.should match %r"arn:aws:sqs:us-east-1:.+:test-create-queue"
12
+ response = sqs.create_queue(queue_name: "test-create-queue")
13
+ expect(response.queue_url).to eq "http://0.0.0.0:4568/test-create-queue"
14
+ response2 = sqs.get_queue_attributes(queue_url: response.queue_url)
15
+ expect(response2.attributes.fetch("QueueArn")).to match %r"arn:aws:sqs:us-east-1:.+:test-create-queue"
11
16
  end
12
17
 
13
18
  specify "GetQueueUrl" do
14
- sqs.queues.create("test-get-queue-url")
15
- queue = sqs.queues.named("test-get-queue-url")
16
- queue.url.should eq "http://0.0.0.0:4568/test-get-queue-url"
19
+ sqs.create_queue(queue_name: "test-get-queue-url")
20
+ response = sqs.get_queue_url(queue_name: "test-get-queue-url")
21
+ expect(response.queue_url).to eq "http://0.0.0.0:4568/test-get-queue-url"
17
22
  end
18
23
 
19
24
  specify "ListQueues" do
20
- sqs.queues.create("test-list-1")
21
- sqs.queues.create("test-list-2")
22
- sqs.queues.map(&:url).should eq [
25
+ sqs.create_queue(queue_name: "test-list-1")
26
+ sqs.create_queue(queue_name: "test-list-2")
27
+ expect(sqs.list_queues.queue_urls).to eq [
23
28
  "http://0.0.0.0:4568/test-list-1",
24
29
  "http://0.0.0.0:4568/test-list-2"
25
30
  ]
26
31
  end
27
32
 
28
33
  specify "ListQueues with prefix" do
29
- sqs.queues.create("test-list-1")
30
- sqs.queues.create("test-list-2")
31
- sqs.queues.create("other-list-3")
32
- sqs.queues.with_prefix("test").map(&:url).should eq [
34
+ sqs.create_queue(queue_name: "test-list-1")
35
+ sqs.create_queue(queue_name: "test-list-2")
36
+ sqs.create_queue(queue_name: "other-list-3")
37
+ expect(sqs.list_queues(queue_name_prefix: "test").queue_urls).to eq [
33
38
  "http://0.0.0.0:4568/test-list-1",
34
39
  "http://0.0.0.0:4568/test-list-2",
35
40
  ]
36
41
  end
37
42
 
38
43
  specify "DeleteQueue" do
39
- url = sqs.queues.create("test-delete").url
40
- sqs.should have(1).queues
41
- sqs.queues[url].delete
42
- sqs.should have(0).queues
44
+ url = sqs.create_queue(queue_name: "test-delete").queue_url
45
+ expect(sqs.list_queues.queue_urls.size).to eq 1
46
+ sqs.delete_queue(queue_url: url)
47
+ expect(sqs.list_queues.queue_urls.size).to eq 0
43
48
  end
44
49
 
45
50
  specify "SetQueueAttributes / GetQueueAttributes" do
51
+ queue_url = sqs.create_queue(queue_name: "my-queue").queue_url
46
52
 
47
- policy = AWS::SQS::Policy.new
48
- policy.allow(
49
- :actions => ['s3:PutObject'],
50
- :resources => "arn:aws:s3:::mybucket/mykey/*",
51
- :principals => :any
52
- ).where(:acl).is("public-read")
53
53
 
54
- queue = sqs.queues.create("my-queue")
55
- queue.policy = policy
54
+ sqs.set_queue_attributes(
55
+ queue_url: queue_url,
56
+ attributes: {
57
+ "DelaySeconds" => "900"
58
+ }
59
+ )
56
60
 
57
- reloaded_queue = sqs.queues.named("my-queue")
58
- reloaded_queue.policy.should eq policy
61
+ response = sqs.get_queue_attributes(
62
+ queue_url: queue_url,
63
+ )
64
+ expect(response.attributes.fetch("DelaySeconds")).to eq "900"
59
65
  end
60
66
 
61
67
  end
@@ -0,0 +1,29 @@
1
+ require "aws-sdk"
2
+ require "fake_sqs/test_integration"
3
+
4
+ # Aws.config[:credentials] = {
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
+ Aws.config.update(
12
+ region: "us-east-1",
13
+ credentials: Aws::Credentials.new("fake", "fake"),
14
+ )
15
+
16
+ db = ENV["SQS_DATABASE"] || ":memory:"
17
+ puts "\n\e[34mRunning specs with database \e[33m#{db}\e[0m"
18
+
19
+ $fake_sqs = FakeSQS::TestIntegration.new(
20
+ database: db,
21
+ sqs_endpoint: "localhost",
22
+ sqs_port: 4568,
23
+ )
24
+
25
+ RSpec.configure do |config|
26
+ config.before(:each, :sqs) { $fake_sqs.start }
27
+ config.before(:each, :sqs) { $fake_sqs.reset }
28
+ config.after(:suite) { $fake_sqs.stop }
29
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,3 @@
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
- db = ENV["SQS_DATABASE"] || ":memory:"
13
- puts "\n\e[34mRunning specs with database \e[33m#{db}\e[0m"
14
- $fake_sqs = FakeSQS::TestIntegration.new(database: db)
15
-
16
1
  RSpec.configure do |config|
17
-
18
- config.treat_symbols_as_metadata_keys_with_true_values = true
19
- config.before(:each, :sqs) { $fake_sqs.start }
20
- config.before(:each, :sqs) { $fake_sqs.reset }
21
- config.after(:suite) { $fake_sqs.stop }
22
-
2
+ config.disable_monkey_patching!
23
3
  end
@@ -12,7 +12,7 @@ class FakeSQS::Actions::TheAction
12
12
 
13
13
  end
14
14
 
15
- describe FakeSQS::API do
15
+ RSpec.describe FakeSQS::API do
16
16
 
17
17
  it "delegates actions to classes" do
18
18
  queues = double :queues
@@ -21,8 +21,8 @@ describe FakeSQS::API do
21
21
 
22
22
  response = api.call("TheAction", {:foo => "bar"})
23
23
 
24
- response[:options].should eq :queues => queues
25
- response[:params].should eq :foo => "bar"
24
+ expect(response[:options]).to eq :queues => queues
25
+ expect(response[:params]).to eq :foo => "bar"
26
26
  end
27
27
 
28
28
  it "raises InvalidAction for unknown actions" do
@@ -37,14 +37,14 @@ describe FakeSQS::API do
37
37
  it "resets queues" do
38
38
  queues = double :queues
39
39
  api = FakeSQS::API.new(:queues => queues)
40
- queues.should_receive(:reset)
40
+ expect(queues).to receive(:reset)
41
41
  api.reset
42
42
  end
43
43
 
44
44
  it "expires messages in queues" do
45
45
  queues = double :queues
46
46
  api = FakeSQS::API.new(:queues => queues)
47
- queues.should_receive(:expire)
47
+ expect(queues).to receive(:expire)
48
48
  api.expire
49
49
  end
50
50
 
@@ -1,6 +1,6 @@
1
1
  require 'fake_sqs/catch_errors'
2
2
 
3
- describe FakeSQS::CatchErrors do
3
+ RSpec.describe FakeSQS::CatchErrors do
4
4
 
5
5
  let(:app) { double :app }
6
6
  let(:error_response) { double :error_response, :status => 500, :body => "X" }
@@ -10,10 +10,10 @@ describe FakeSQS::CatchErrors do
10
10
  context "when the app behaves normally" do
11
11
 
12
12
  let(:normal_response) { double :normal_response }
13
- before { app.stub(:call => normal_response) }
13
+ before { allow(app).to receive(:call).and_return(normal_response) }
14
14
 
15
15
  it "doesn't modify normal responses" do
16
- catch_errors.call({}).should eq normal_response
16
+ expect(catch_errors.call({})).to eq normal_response
17
17
  end
18
18
 
19
19
  end
@@ -21,21 +21,21 @@ describe FakeSQS::CatchErrors do
21
21
  context "when the app raises an exception" do
22
22
 
23
23
  let(:error) { RuntimeError.new("it went wrong") }
24
- before { app.stub(:call).and_raise(error) }
24
+ before { allow(app).to receive(:call).and_raise(error) }
25
25
 
26
26
  it "cathes and processes errors" do
27
- response.should_receive(:new).with(error)
27
+ expect(response).to receive(:new).with(error)
28
28
  catch_errors.call({})
29
29
  end
30
30
 
31
31
  it "sets the status determined by the error response" do
32
- error_response.stub(:status => 123)
33
- catch_errors.call({}).fetch(0).should eq 123
32
+ allow(error_response).to receive(:status).and_return(123)
33
+ expect(catch_errors.call({}).fetch(0)).to eq 123
34
34
  end
35
35
 
36
36
  it "set the body determined by the error response" do
37
- error_response.stub(:body => "foobar")
38
- catch_errors.call({}).fetch(2).should eq ["foobar"]
37
+ allow(error_response).to receive(:body).and_return("foobar")
38
+ expect(catch_errors.call({}).fetch(2)).to eq ["foobar"]
39
39
  end
40
40
 
41
41
  end
@@ -1,6 +1,6 @@
1
1
  require 'fake_sqs/collection_view'
2
2
 
3
- describe FakeSQS::CollectionView do
3
+ RSpec.describe FakeSQS::CollectionView do
4
4
 
5
5
  def wrap(collection)
6
6
  FakeSQS::CollectionView.new(collection)
@@ -9,33 +9,33 @@ describe FakeSQS::CollectionView do
9
9
  it 'should correctly wrap an array' do
10
10
  array = %w{one two three four}
11
11
  view = wrap(array)
12
- view[0].should == 'one'
13
- view[1].should == 'two'
14
- view[2].should == 'three'
15
- view[3].should == 'four'
12
+ expect(view[0]).to eq 'one'
13
+ expect(view[1]).to eq 'two'
14
+ expect(view[2]).to eq 'three'
15
+ expect(view[3]).to eq 'four'
16
16
  end
17
17
 
18
18
  it 'should correctly wrap a hash' do
19
19
  hash = { :one => 1, :two => 2, :three => 3 }
20
20
  view = wrap(hash)
21
- view[:one].should == 1
22
- view[:two].should == 2
23
- view[:three].should == 3
21
+ expect(view[:one]).to eq 1
22
+ expect(view[:two]).to eq 2
23
+ expect(view[:three]).to eq 3
24
24
  end
25
25
 
26
26
  it 'should respond to empty correctly' do
27
- wrap([]).should be_empty
28
- wrap({'one' => 1}).should_not be_empty
27
+ expect(wrap([])).to be_empty
28
+ expect(wrap({'one' => 1})).to_not be_empty
29
29
  end
30
30
 
31
31
  it 'should be enumerable' do
32
32
  result = wrap([1, 2, 3]).map { |i| i * i }
33
- result.should == [1, 4, 9]
33
+ expect(result).to eq [1, 4, 9]
34
34
  end
35
35
 
36
36
  it 'should respond to size/length' do
37
- wrap([1, 2, 3]).size.should == 3
38
- wrap([]).length.should == 0
37
+ expect(wrap([1, 2, 3]).size).to eq 3
38
+ expect(wrap([]).size).to eq 0
39
39
  end
40
40
 
41
- end
41
+ end
@@ -2,7 +2,7 @@ require 'fake_sqs/error_response'
2
2
  require 'active_support/core_ext/hash'
3
3
  require 'verbose_hash_fetch'
4
4
 
5
- describe FakeSQS::ErrorResponse do
5
+ RSpec.describe FakeSQS::ErrorResponse do
6
6
 
7
7
  module FakeSQS
8
8
  MissingCredentials = Class.new(RuntimeError)
@@ -14,13 +14,13 @@ describe FakeSQS::ErrorResponse do
14
14
  it "picks the right error status" do
15
15
  error = FakeSQS::MissingCredentials.new("message")
16
16
  response = FakeSQS::ErrorResponse.new(error)
17
- response.status.should eq 401
17
+ expect(response.status).to eq 401
18
18
  end
19
19
 
20
20
  it "uses 400 as default status" do
21
21
  error = ErrorUnknownToSQS.new("message")
22
22
  response = FakeSQS::ErrorResponse.new(error)
23
- response.status.should eq 500
23
+ expect(response.status).to eq 500
24
24
  end
25
25
 
26
26
  end
@@ -32,32 +32,32 @@ describe FakeSQS::ErrorResponse do
32
32
  let(:data) { Hash.from_xml(response.body) }
33
33
 
34
34
  it "uses the error class name as error code" do
35
- data.fetch("ErrorResponse").fetch("Error").fetch("Code").should eq "MissingCredentials"
35
+ expect(data.fetch("ErrorResponse").fetch("Error").fetch("Code")).to eq "MissingCredentials"
36
36
  end
37
37
 
38
38
  it "uses InternalError as code for unknown errors" do
39
39
  error = ErrorUnknownToSQS.new("the message")
40
40
  response = FakeSQS::ErrorResponse.new(error)
41
41
  data = Hash.from_xml(response.body)
42
- data.fetch("ErrorResponse").fetch("Error").fetch("Code").should eq "InternalError"
42
+ expect(data.fetch("ErrorResponse").fetch("Error").fetch("Code")).to eq "InternalError"
43
43
  end
44
44
 
45
45
  it "uses the to_s of the error as message" do
46
- data.fetch("ErrorResponse").fetch("Error").fetch("Message").should eq "the message"
46
+ expect(data.fetch("ErrorResponse").fetch("Error").fetch("Message")).to eq "the message"
47
47
  end
48
48
 
49
49
  it "has a request id" do
50
- data.fetch("ErrorResponse").fetch("RequestId").should have(36).characters
50
+ expect(data.fetch("ErrorResponse").fetch("RequestId").size).to eq 36
51
51
  end
52
52
 
53
53
  it "uses Sender as type for 4xx responses" do
54
- response.stub(:status => 400)
55
- data.fetch("ErrorResponse").fetch("Error").fetch("Type").should eq "Sender"
54
+ allow(response).to receive(:status).and_return(400)
55
+ expect(data.fetch("ErrorResponse").fetch("Error").fetch("Type")).to eq "Sender"
56
56
  end
57
57
 
58
58
  it "uses Receiver as type for 5xx responses" do
59
- response.stub(:status => 500)
60
- data.fetch("ErrorResponse").fetch("Error").fetch("Type").should eq "Receiver"
59
+ allow(response).to receive(:status).and_return(500)
60
+ expect(data.fetch("ErrorResponse").fetch("Error").fetch("Type")).to eq "Receiver"
61
61
  end
62
62
 
63
63
  end
@@ -1,12 +1,12 @@
1
1
  require 'fake_sqs/message'
2
2
 
3
- describe FakeSQS::Message do
3
+ RSpec.describe FakeSQS::Message do
4
4
 
5
5
  describe "#body" do
6
6
 
7
7
  it "is extracted from the MessageBody" do
8
8
  message = create_message("MessageBody" => "abc")
9
- message.body.should eq "abc"
9
+ expect(message.body).to eq "abc"
10
10
  end
11
11
 
12
12
  end
@@ -15,7 +15,7 @@ describe FakeSQS::Message do
15
15
 
16
16
  it "is calculated from body" do
17
17
  message = create_message("MessageBody" => "abc")
18
- message.md5.should eq "900150983cd24fb0d6963f7d28e17f72"
18
+ expect(message.md5).to eq "900150983cd24fb0d6963f7d28e17f72"
19
19
  end
20
20
 
21
21
  end
@@ -24,7 +24,7 @@ describe FakeSQS::Message do
24
24
 
25
25
  it "is generated" do
26
26
  message = create_message
27
- message.id.should have(36).characters
27
+ expect(message.id.size).to eq 36
28
28
  end
29
29
 
30
30
  end
@@ -36,26 +36,26 @@ describe FakeSQS::Message do
36
36
  end
37
37
 
38
38
  it 'should default to nil' do
39
- message.visibility_timeout.should be_nil
39
+ expect(message.visibility_timeout).to eq nil
40
40
  end
41
41
 
42
42
  it 'should be expired when it is nil' do
43
- message.should be_expired
43
+ expect(message).to be_expired
44
44
  end
45
45
 
46
46
  it 'should be expired if set to a previous time' do
47
47
  message.visibility_timeout = Time.now - 1
48
- message.should be_expired
48
+ expect(message).to be_expired
49
49
  end
50
50
 
51
51
  it 'should not be expired at a future date' do
52
52
  message.visibility_timeout = Time.now + 1
53
- message.should_not be_expired
53
+ expect(message).not_to be_expired
54
54
  end
55
55
 
56
56
  it 'should not be expired when set to expire at a future date' do
57
57
  message.expire_at(5)
58
- message.visibility_timeout.should be >=(Time.now + 4)
58
+ expect(message.visibility_timeout).to be >=(Time.now + 4)
59
59
  end
60
60
 
61
61
  end
@@ -1,12 +1,12 @@
1
1
  require 'fake_sqs/queue_factory'
2
2
 
3
- describe FakeSQS::QueueFactory do
3
+ RSpec.describe FakeSQS::QueueFactory do
4
4
 
5
5
  it "builds queues with a message factory" do
6
6
  message_factory = double :message_factory
7
7
  queue = double :queue
8
8
  queue_factory = FakeSQS::QueueFactory.new(message_factory: message_factory, queue: queue)
9
- queue.should_receive(:new).with(message_factory: message_factory, name: "Foo")
9
+ expect(queue).to receive(:new).with(message_factory: message_factory, name: "Foo")
10
10
  queue_factory.new(name: "Foo")
11
11
  end
12
12
 
@@ -1,7 +1,7 @@
1
1
  require 'fake_sqs/queue'
2
2
  require 'fake_sqs/message'
3
3
 
4
- describe FakeSQS::Queue do
4
+ RSpec.describe FakeSQS::Queue do
5
5
 
6
6
  class MessageFactory
7
7
  def new(options = {})
@@ -15,20 +15,20 @@ describe FakeSQS::Queue do
15
15
  describe "#send_message" do
16
16
 
17
17
  it "adds a message" do
18
- queue.should have(0).messages
18
+ expect(queue.messages.size).to eq 0
19
19
  send_message
20
- queue.should have(1).messages
20
+ expect(queue.messages.size).to eq 1
21
21
  end
22
22
 
23
23
  it "returns the message" do
24
24
  message = double.as_null_object
25
- message_factory.stub(:new).and_return(message)
26
- send_message.should eq message
25
+ allow(message_factory).to receive(:new).and_return(message)
26
+ expect(send_message).to eq message
27
27
  end
28
28
 
29
29
  it "uses the message factory" do
30
30
  options = { "MessageBody" => "abc" }
31
- message_factory.should_receive(:new).with(options)
31
+ expect(message_factory).to receive(:new).with(options)
32
32
  send_message(options)
33
33
  end
34
34
 
@@ -39,7 +39,7 @@ describe FakeSQS::Queue do
39
39
  it "gets the message" do
40
40
  sent = send_message
41
41
  received = receive_message
42
- received.values.first.should eq sent
42
+ expect(received.values.first).to eq sent
43
43
  end
44
44
 
45
45
  it "gets you a random message" do
@@ -60,10 +60,10 @@ describe FakeSQS::Queue do
60
60
  reset_queue
61
61
  end
62
62
 
63
- (indexes[:first] + indexes[:second]).should eq sample_group
63
+ expect(indexes[:first] + indexes[:second]).to eq sample_group
64
64
 
65
- indexes[:first].should be_within(ten_percent).of(half_sample_group)
66
- indexes[:second].should be_within(ten_percent).of(half_sample_group)
65
+ expect(indexes[:first]).to be_within(ten_percent).of(half_sample_group)
66
+ expect(indexes[:second]).to be_within(ten_percent).of(half_sample_group)
67
67
  end
68
68
 
69
69
  it "cannot get received messages" do
@@ -75,9 +75,9 @@ describe FakeSQS::Queue do
75
75
  received_first = receive_message.values.first
76
76
 
77
77
  if received_first == sent_first
78
- receive_message.values.first.should eq sent_second
78
+ expect(receive_message.values.first).to eq sent_second
79
79
  else
80
- receive_message.values.first.should eq sent_first
80
+ expect(receive_message.values.first).to eq sent_first
81
81
  end
82
82
  reset_queue
83
83
  end
@@ -87,23 +87,23 @@ describe FakeSQS::Queue do
87
87
 
88
88
  send_message
89
89
 
90
- queue.should have(0).messages_in_flight
91
- queue.attributes["ApproximateNumberOfMessagesNotVisible"].should eq 0
92
- queue.attributes["ApproximateNumberOfMessages"].should eq 1
90
+ expect(queue.messages_in_flight.size).to eq 0
91
+ expect(queue.attributes["ApproximateNumberOfMessagesNotVisible"]).to eq 0
92
+ expect(queue.attributes["ApproximateNumberOfMessages"]).to eq 1
93
93
 
94
94
  receive_message
95
95
 
96
- queue.should have(1).messages_in_flight
97
- queue.attributes["ApproximateNumberOfMessagesNotVisible"].should eq 1
98
- queue.attributes["ApproximateNumberOfMessages"].should eq 0
96
+ expect(queue.messages_in_flight.size).to eq 1
97
+ expect(queue.attributes["ApproximateNumberOfMessagesNotVisible"]).to eq 1
98
+ expect(queue.attributes["ApproximateNumberOfMessages"]).to eq 0
99
99
  end
100
100
 
101
101
  it "gets multiple message" do
102
102
  sent_first = send_message
103
103
  sent_second = send_message
104
104
  messages = receive_message("MaxNumberOfMessages" => "2")
105
- messages.size.should eq 2
106
- messages.values.should match_array [ sent_first, sent_second ]
105
+ expect(messages.size).to eq 2
106
+ expect(messages.values).to match_array [ sent_first, sent_second ]
107
107
  end
108
108
 
109
109
  it "won't accept more than 10 message" do
@@ -113,7 +113,7 @@ describe FakeSQS::Queue do
113
113
  end
114
114
 
115
115
  it "won't error on empty queues" do
116
- receive_message.should eq({})
116
+ expect(receive_message).to eq({})
117
117
  end
118
118
 
119
119
  end
@@ -124,10 +124,10 @@ describe FakeSQS::Queue do
124
124
  send_message
125
125
  receipt = receive_message.keys.first
126
126
 
127
- queue.should have(1).messages_in_flight
127
+ expect(queue.messages_in_flight.size).to eq 1
128
128
  queue.delete_message(receipt)
129
- queue.should have(0).messages_in_flight
130
- queue.should have(0).messages
129
+ expect(queue.messages_in_flight.size).to eq 0
130
+ expect(queue.messages.size).to eq 0
131
131
  end
132
132
 
133
133
  it "won't raise if the receipt is unknown" do
@@ -140,7 +140,7 @@ describe FakeSQS::Queue do
140
140
 
141
141
  it "adds to it's queue attributes" do
142
142
  queue.add_queue_attributes("foo" => "bar")
143
- queue.attributes.should eq(
143
+ expect(queue.attributes).to eq(
144
144
  "foo" => "bar",
145
145
  "QueueArn" => queue.arn,
146
146
  "ApproximateNumberOfMessages" => 0,
@@ -1,7 +1,7 @@
1
1
  require 'fake_sqs/queues'
2
2
  require 'fake_sqs/memory_database'
3
3
 
4
- describe FakeSQS::Queues do
4
+ RSpec.describe FakeSQS::Queues do
5
5
 
6
6
  let(:fake_database) { FakeSQS::MemoryDatabase.new }
7
7
  let(:queue_factory) { double :queue_factory, :new => double }
@@ -10,21 +10,21 @@ describe FakeSQS::Queues do
10
10
  describe "#create" do
11
11
 
12
12
  it "creates new queues" do
13
- queues.list.size.should eq 0
13
+ expect(queues.list.size).to eq 0
14
14
  create_queue("test")
15
- queues.list.size.should eq 1
15
+ expect(queues.list.size).to eq 1
16
16
  end
17
17
 
18
18
  it "uses the queue factory" do
19
19
  params = double :params
20
- queue_factory.should_receive(:new).with(params)
20
+ expect(queue_factory).to receive(:new).with(params)
21
21
  create_queue("test", params)
22
22
  end
23
23
 
24
24
  it "returns the queue" do
25
25
  queue = double
26
- queue_factory.stub(:new).and_return(queue)
27
- create_queue("test").should eq queue
26
+ allow(queue_factory).to receive(:new).and_return(queue)
27
+ expect(create_queue("test")).to eq queue
28
28
  end
29
29
 
30
30
  it "cannot create a queue with the same name" do
@@ -40,9 +40,9 @@ describe FakeSQS::Queues do
40
40
 
41
41
  it "deletes an existing queue" do
42
42
  create_queue("test")
43
- queues.list.size.should eq 1
43
+ expect(queues.list.size).to eq 1
44
44
  queues.delete("test")
45
- queues.list.size.should eq 0
45
+ expect(queues.list.size).to eq 0
46
46
  end
47
47
 
48
48
  it "cannot delete an non-existing queue" do
@@ -58,14 +58,14 @@ describe FakeSQS::Queues do
58
58
  it "returns all the queues" do
59
59
  queue1 = create_queue("test-1")
60
60
  queue2 = create_queue("test-2")
61
- queues.list.should eq [ queue1, queue2 ]
61
+ expect(queues.list).to eq [ queue1, queue2 ]
62
62
  end
63
63
 
64
64
  it "can be filtered by prefix" do
65
65
  queue1 = create_queue("test-1")
66
66
  queue2 = create_queue("test-2")
67
67
  _ = create_queue("other-3")
68
- queues.list("QueueNamePrefix" => "test").should eq [ queue1, queue2 ]
68
+ expect(queues.list("QueueNamePrefix" => "test")).to eq [ queue1, queue2 ]
69
69
  end
70
70
 
71
71
  end
@@ -74,7 +74,7 @@ describe FakeSQS::Queues do
74
74
 
75
75
  it "finds the queue by name" do
76
76
  queue = create_queue("test")
77
- queues.get("test").should eq queue
77
+ expect(queues.get("test")).to eq queue
78
78
  end
79
79
 
80
80
  it "cannot get the queue if it doesn't exist" do
@@ -90,9 +90,9 @@ describe FakeSQS::Queues do
90
90
  it "clears all queues" do
91
91
  create_queue("foo")
92
92
  create_queue("bar")
93
- queues.list.size.should eq 2
93
+ expect(queues.list.size).to eq 2
94
94
  queues.reset
95
- queues.list.size.should eq 0
95
+ expect(queues.list.size).to eq 0
96
96
  end
97
97
 
98
98
  end
@@ -2,11 +2,11 @@ require 'fake_sqs/responder'
2
2
  require 'active_support/core_ext/hash'
3
3
  require 'verbose_hash_fetch'
4
4
 
5
- describe FakeSQS::Responder do
5
+ RSpec.describe FakeSQS::Responder do
6
6
 
7
7
  it "yields xml" do
8
- xml = subject.call :GetQueueUrl do |xml|
9
- xml.QueueUrl "example.com"
8
+ xml = subject.call :GetQueueUrl do |x|
9
+ x.QueueUrl "example.com"
10
10
  end
11
11
 
12
12
  data = Hash.from_xml(xml)
@@ -14,7 +14,7 @@ describe FakeSQS::Responder do
14
14
  fetch("GetQueueUrlResponse").
15
15
  fetch("GetQueueUrlResult").
16
16
  fetch("QueueUrl")
17
- url.should eq "example.com"
17
+ expect(url).to eq "example.com"
18
18
  end
19
19
 
20
20
  it "skips result if no block is given" do
@@ -23,12 +23,12 @@ describe FakeSQS::Responder do
23
23
  data = Hash.from_xml(xml)
24
24
 
25
25
  response = data.fetch("DeleteQueueResponse")
26
- response.should have_key("ResponseMetadata")
27
- response.should_not have_key("DeleteQueueResult")
26
+ expect(response).to have_key("ResponseMetadata")
27
+ expect(response).not_to have_key("DeleteQueueResult")
28
28
  end
29
29
 
30
30
  it "has metadata" do
31
- xml = subject.call :GetQueueUrl do |xml|
31
+ xml = subject.call :GetQueueUrl do |x|
32
32
  end
33
33
 
34
34
  data = Hash.from_xml(xml)
@@ -38,7 +38,7 @@ describe FakeSQS::Responder do
38
38
  fetch("ResponseMetadata").
39
39
  fetch("RequestId")
40
40
 
41
- request_id.should have(36).characters
41
+ expect(request_id.size).to eq 36
42
42
  end
43
43
 
44
44
  end
@@ -1,6 +1,6 @@
1
1
  require 'fake_sqs/show_output'
2
2
 
3
- describe FakeSQS::ShowOutput do
3
+ RSpec.describe FakeSQS::ShowOutput do
4
4
 
5
5
  after do
6
6
  $stdout = STDOUT
@@ -11,12 +11,12 @@ describe FakeSQS::ShowOutput do
11
11
  $stdout = StringIO.new
12
12
  middleware = FakeSQS::ShowOutput.new(app)
13
13
  env = {"rack.input" => ""}
14
- app.should_receive(:call).with(env).and_return([200, {}, ["<xml>"]])
14
+ expect(app).to receive(:call).with(env).and_return([200, {}, ["<xml>"]])
15
15
 
16
16
  middleware.call(env)
17
17
 
18
18
  $stdout.rewind
19
- $stdout.read.should eq "--- {}\n\n<xml>\n"
19
+ expect($stdout.read).to eq "--- {}\n\n<xml>\n"
20
20
  end
21
21
 
22
22
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: aws-sdk
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '2.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '2.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faraday
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -186,6 +186,7 @@ files:
186
186
  - lib/fake_sqs/web_interface.rb
187
187
  - spec/acceptance/message_actions_spec.rb
188
188
  - spec/acceptance/queue_actions_spec.rb
189
+ - spec/integration_spec_helper.rb
189
190
  - spec/spec_helper.rb
190
191
  - spec/unit/api_spec.rb
191
192
  - spec/unit/catch_errors_spec.rb
@@ -217,13 +218,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
218
  version: '0'
218
219
  requirements: []
219
220
  rubyforge_project:
220
- rubygems_version: 2.2.0
221
+ rubygems_version: 2.4.5
221
222
  signing_key:
222
223
  specification_version: 4
223
224
  summary: Provides a fake SQS server that you can run locally to test against
224
225
  test_files:
225
226
  - spec/acceptance/message_actions_spec.rb
226
227
  - spec/acceptance/queue_actions_spec.rb
228
+ - spec/integration_spec_helper.rb
227
229
  - spec/spec_helper.rb
228
230
  - spec/unit/api_spec.rb
229
231
  - spec/unit/catch_errors_spec.rb
@@ -235,3 +237,4 @@ test_files:
235
237
  - spec/unit/queues_spec.rb
236
238
  - spec/unit/responder_spec.rb
237
239
  - spec/unit/show_output_spec.rb
240
+ has_rdoc: