batch_api 0.2.1 → 0.3.0

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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/changelog.md +14 -0
  3. data/lib/batch_api/configuration.rb +1 -1
  4. data/lib/batch_api/internal_middleware/decode_json_body.rb +7 -3
  5. data/lib/batch_api/operation/rack.rb +4 -1
  6. data/lib/batch_api/version.rb +1 -1
  7. data/readme.md +2 -2
  8. data/spec/dummy/Gemfile +1 -0
  9. data/spec/dummy/Gemfile.lock +8 -0
  10. data/spec/dummy/bin/bundle +3 -0
  11. data/spec/dummy/bin/rails +4 -0
  12. data/spec/dummy/bin/rake +4 -0
  13. data/spec/dummy/bin/setup +29 -0
  14. data/spec/dummy/config/application.rb +6 -37
  15. data/spec/dummy/config/boot.rb +2 -9
  16. data/spec/dummy/config/environment.rb +3 -3
  17. data/spec/dummy/config/environments/development.rb +22 -18
  18. data/spec/dummy/config/environments/production.rb +46 -34
  19. data/spec/dummy/config/environments/test.rb +19 -14
  20. data/spec/dummy/config/initializers/assets.rb +11 -0
  21. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  22. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  23. data/spec/dummy/config/initializers/inflections.rb +6 -5
  24. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  25. data/spec/dummy/config/initializers/session_store.rb +1 -6
  26. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  27. data/spec/dummy/config/locales/en.yml +20 -2
  28. data/spec/dummy/config/secrets.yml +22 -0
  29. data/spec/dummy/log/test.log +7369 -46081
  30. data/spec/lib/batch_api_spec.rb +3 -3
  31. data/spec/lib/batch_error_spec.rb +3 -3
  32. data/spec/lib/configuration_spec.rb +3 -3
  33. data/spec/lib/error_wrapper_spec.rb +20 -20
  34. data/spec/lib/internal_middleware/decode_json_body_spec.rb +13 -6
  35. data/spec/lib/internal_middleware/response_filter_spec.rb +3 -3
  36. data/spec/lib/internal_middleware_spec.rb +15 -13
  37. data/spec/lib/operation/rack_spec.rb +58 -50
  38. data/spec/lib/operation/rails_spec.rb +10 -10
  39. data/spec/lib/processor/executor_spec.rb +5 -5
  40. data/spec/lib/processor/sequential_spec.rb +10 -10
  41. data/spec/lib/processor_spec.rb +23 -21
  42. data/spec/lib/rack_middleware_spec.rb +17 -17
  43. data/spec/lib/response_spec.rb +9 -9
  44. data/spec/{integration → rack-integration}/rails_spec.rb +3 -3
  45. data/spec/{integration → rack-integration}/shared_examples.rb +24 -18
  46. data/spec/{integration → rack-integration}/sinatra_integration_spec.rb +5 -0
  47. data/spec/spec_helper.rb +15 -1
  48. data/spec/support/sinatra_xhr.rb +13 -0
  49. metadata +47 -135
  50. data/spec/dummy/db/development.sqlite3 +0 -0
  51. data/spec/dummy/log/development.log +0 -1742
@@ -4,17 +4,17 @@ require 'batch_api'
4
4
  describe BatchApi do
5
5
  describe ".config" do
6
6
  it "has a reader for config" do
7
- BatchApi.config.should_not be_nil
7
+ expect(BatchApi.config).not_to be_nil
8
8
  end
9
9
 
10
10
  it "provides a default config" do
11
- BatchApi.config.should be_a(BatchApi::Configuration)
11
+ expect(BatchApi.config).to be_a(BatchApi::Configuration)
12
12
  end
13
13
  end
14
14
 
15
15
  describe ".rails?" do
16
16
  it "returns a value we can't test based on whether Rails is defined" do
17
- BatchApi.rails?.should_not be_nil
17
+ expect(BatchApi.rails?).not_to be_nil
18
18
  end
19
19
  end
20
20
  end
@@ -9,15 +9,15 @@ describe BatchApi::Errors::BatchError do
9
9
  BatchApi::Errors::MalformedOperationError
10
10
  ].each do |klass|
11
11
  it "provides a #{klass} error based on ArgumentError" do
12
- klass.superclass.should == ArgumentError
12
+ expect(klass.superclass).to eq(ArgumentError)
13
13
  end
14
14
 
15
15
  it "is is also a BatchError" do
16
- klass.new.should be_a(BatchApi::Errors::BatchError)
16
+ expect(klass.new).to be_a(BatchApi::Errors::BatchError)
17
17
  end
18
18
 
19
19
  it "has a status code of 422" do
20
- klass.new.status_code.should == 422
20
+ expect(klass.new.status_code).to eq(422)
21
21
  end
22
22
  end
23
23
  end
@@ -15,13 +15,13 @@ module BatchApi
15
15
  opt, defa = option, default
16
16
  describe "##{opt}" do
17
17
  it "has an accessor for #{opt}" do
18
- stubby = stub
18
+ stubby = double
19
19
  config.send("#{opt}=", stubby)
20
- config.send(opt).should == stubby
20
+ expect(config.send(opt)).to eq(stubby)
21
21
  end
22
22
 
23
23
  it "defaults #{opt} to #{defa.inspect}" do
24
- config.send(opt).should == defa
24
+ expect(config.send(opt)).to eq(defa)
25
25
  end
26
26
  end
27
27
  end
@@ -12,57 +12,57 @@ describe BatchApi::ErrorWrapper do
12
12
 
13
13
  describe "#body" do
14
14
  it "includes the message in the body" do
15
- error.body[:error][:message].should == exception.message
15
+ expect(error.body[:error][:message]).to eq(exception.message)
16
16
  end
17
17
 
18
18
  it "includes the backtrace if it should be there" do
19
- error.stub(:expose_backtrace?).and_return(true)
20
- error.body[:error][:backtrace].should == exception.backtrace
19
+ allow(error).to receive(:expose_backtrace?).and_return(true)
20
+ expect(error.body[:error][:backtrace]).to eq(exception.backtrace)
21
21
  end
22
22
 
23
23
  it "includes the backtrace if it should be there" do
24
- error.stub(:expose_backtrace?).and_return(false)
25
- error.body[:backtrace].should be_nil
24
+ allow(error).to receive(:expose_backtrace?).and_return(false)
25
+ expect(error.body[:backtrace]).to be_nil
26
26
  end
27
27
  end
28
28
 
29
29
  describe "#render" do
30
30
  it "returns the appropriate status" do
31
- status = stub
32
- error.stub(:status_code).and_return(status)
33
- error.render[0].should == status
31
+ status = double
32
+ allow(error).to receive(:status_code).and_return(status)
33
+ expect(error.render[0]).to eq(status)
34
34
  end
35
35
 
36
36
  it "returns appropriate content type" do
37
- ctype = stub
38
- BatchApi::RackMiddleware.stub(:content_type).and_return(ctype)
39
- error.render[1].should == ctype
37
+ ctype = double
38
+ allow(BatchApi::RackMiddleware).to receive(:content_type).and_return(ctype)
39
+ expect(error.render[1]).to eq(ctype)
40
40
  end
41
41
 
42
42
  it "returns the JSONified body as the 2nd" do
43
- error.render[2].should == [MultiJson.dump(error.body)]
43
+ expect(error.render[2]).to eq([MultiJson.dump(error.body)])
44
44
  end
45
45
  end
46
46
 
47
47
  describe "#status_code" do
48
48
  it "returns 500 by default" do
49
- error.status_code.should == 500
49
+ expect(error.status_code).to eq(500)
50
50
  end
51
51
 
52
52
  it "returns another status code if the error supports that" do
53
53
  err = StandardError.new
54
- code = stub
55
- err.stub(:status_code).and_return(code)
56
- BatchApi::ErrorWrapper.new(err).status_code.should == code
54
+ code = double
55
+ allow(err).to receive(:status_code).and_return(code)
56
+ expect(BatchApi::ErrorWrapper.new(err).status_code).to eq(code)
57
57
  end
58
58
  end
59
59
 
60
60
  describe ".expose_backtrace?" do
61
61
  it "returns false if Rails.env.production?" do
62
- Rails.env.stub(:production?).and_return(true)
63
- BatchApi::ErrorWrapper.expose_backtrace?.should be_false
64
- Rails.env.stub(:production?).and_return(false)
65
- BatchApi::ErrorWrapper.expose_backtrace?.should be_true
62
+ allow(Rails).to receive(:env).and_return(double(test?: false, production?: true, development?: false))
63
+ expect(BatchApi::ErrorWrapper.expose_backtrace?).to be_falsey
64
+ allow(Rails.env).to receive(:production?).and_return(false)
65
+ expect(BatchApi::ErrorWrapper.expose_backtrace?).to be_truthy
66
66
  end
67
67
  end
68
68
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BatchApi::InternalMiddleware::DecodeJsonBody do
4
- let(:app) { stub("app", call: result) }
4
+ let(:app) { double("app", call: result) }
5
5
  let(:decoder) { BatchApi::InternalMiddleware::DecodeJsonBody.new(app) }
6
- let(:env) { stub("env") }
6
+ let(:env) { double("env") }
7
7
  let(:json) { {"data" => "is_json", "more" => {"hi" => "there"} } }
8
8
  let(:result) {
9
9
  BatchApi::Response.new([
@@ -17,20 +17,27 @@ describe BatchApi::InternalMiddleware::DecodeJsonBody do
17
17
  context "for json results" do
18
18
  it "decodes JSON results for application/json responses" do
19
19
  result = decoder.call(env)
20
- result.body.should == json
20
+ expect(result.body).to eq(json)
21
21
  end
22
22
 
23
23
  it "doesn't change anything else" do
24
24
  result = decoder.call(env)
25
- result.status.should == 200
26
- result.headers.should == {"Content-Type" => "application/json"}
25
+ expect(result.status).to eq(200)
26
+ expect(result.headers).to eq({"Content-Type" => "application/json"})
27
27
  end
28
28
  end
29
29
 
30
30
  context "for non-JSON responses" do
31
31
  it "doesn't decode" do
32
32
  result.headers = {"Content-Type" => "text/html"}
33
- decoder.call(env).body.should == MultiJson.dump(json)
33
+ expect(decoder.call(env).body).to eq(MultiJson.dump(json))
34
+ end
35
+ end
36
+
37
+ context "for empty responses" do
38
+ it "doesn't try to parse" do
39
+ result.body = ""
40
+ expect(decoder.call(env).body).to eq("")
34
41
  end
35
42
  end
36
43
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BatchApi::InternalMiddleware::ResponseFilter do
4
- let(:app) { stub("app", call: result) }
4
+ let(:app) { double("app", call: result) }
5
5
  let(:surpressor) { BatchApi::InternalMiddleware::ResponseFilter.new(app) }
6
6
  let(:env) { {
7
- op: stub("operation", options: {"silent" => true})
7
+ op: double("operation", options: {"silent" => true})
8
8
  } }
9
9
 
10
10
  let(:result) {
@@ -20,7 +20,7 @@ describe BatchApi::InternalMiddleware::ResponseFilter do
20
20
  context "for successful (200-299) results" do
21
21
  it "empties the response so its as_json is empty" do
22
22
  surpressor.call(env)
23
- result.as_json.should == {}
23
+ expect(result.as_json).to eq({})
24
24
  end
25
25
  end
26
26
 
@@ -20,7 +20,7 @@ describe BatchApi::InternalMiddleware do
20
20
  builder.instance_eval(
21
21
  &BatchApi::InternalMiddleware::DEFAULT_BATCH_MIDDLEWARE
22
22
  )
23
- builder.middlewares.should be_empty
23
+ expect(builder.middlewares).to be_empty
24
24
  end
25
25
 
26
26
  describe "internal middleware defaults" do
@@ -31,38 +31,40 @@ describe BatchApi::InternalMiddleware do
31
31
  end
32
32
 
33
33
  it "builds a per-op middleware with the response silencer" do
34
- builder.middlewares[0].should ==
34
+ expect(builder.middlewares[0]).to eq(
35
35
  [BatchApi::InternalMiddleware::ResponseFilter, []]
36
+ )
36
37
  end
37
38
 
38
39
  it "builds a per-op middleware with the JSON decoder" do
39
- builder.middlewares[1].should ==
40
+ expect(builder.middlewares[1]).to eq(
40
41
  [BatchApi::InternalMiddleware::DecodeJsonBody, []]
42
+ )
41
43
  end
42
44
  end
43
45
 
44
46
  describe ".batch_stack" do
45
47
  # we can't use stubs inside the procs since they're instance_eval'd
46
48
  let(:global_config) { Proc.new { use "Global" } }
47
- let(:strategy) { stub("strategy") }
48
- let(:processor) { stub("processor", strategy: strategy) }
49
+ let(:strategy) { double("strategy") }
50
+ let(:processor) { double("processor", strategy: strategy) }
49
51
  let(:stack) { BatchApi::InternalMiddleware.batch_stack(processor) }
50
52
 
51
53
  before :each do
52
- BatchApi.config.stub(:batch_middleware).and_return(global_config)
54
+ allow(BatchApi.config).to receive(:batch_middleware).and_return(global_config)
53
55
  stub_const("Middleware::Builder", FakeBuilder)
54
56
  end
55
57
 
56
58
  it "builds the stack with the right number of wares" do
57
- stack.middlewares.length.should == 2
59
+ expect(stack.middlewares.length).to eq(2)
58
60
  end
59
61
 
60
62
  it "builds a middleware stack starting with the configured global wares" do
61
- stack.middlewares[0].first.should == "Global"
63
+ expect(stack.middlewares[0].first).to eq("Global")
62
64
  end
63
65
 
64
66
  it "inserts the appropriate strategy from the processor" do
65
- stack.middlewares[1].first.should == strategy
67
+ expect(stack.middlewares[1].first).to eq(strategy)
66
68
  end
67
69
  end
68
70
 
@@ -72,20 +74,20 @@ describe BatchApi::InternalMiddleware do
72
74
  let(:stack) { BatchApi::InternalMiddleware.operation_stack }
73
75
 
74
76
  before :each do
75
- BatchApi.config.stub(:operation_middleware).and_return(op_config)
77
+ allow(BatchApi.config).to receive(:operation_middleware).and_return(op_config)
76
78
  stub_const("Middleware::Builder", FakeBuilder)
77
79
  end
78
80
 
79
81
  it "builds the stack with the right number of wares" do
80
- stack.middlewares.length.should == 2
82
+ expect(stack.middlewares.length).to eq(2)
81
83
  end
82
84
 
83
85
  it "builds a middleware stack including the configured per-op wares" do
84
- stack.middlewares[0].first.should == "Op"
86
+ expect(stack.middlewares[0].first).to eq("Op")
85
87
  end
86
88
 
87
89
  it "builds a middleware stack ending with the executor" do
88
- stack.middlewares[1].first.should == BatchApi::Processor::Executor
90
+ expect(stack.middlewares[1].first).to eq(BatchApi::Processor::Executor)
89
91
  end
90
92
  end
91
93
  end
@@ -12,7 +12,7 @@ describe BatchApi::Operation::Rack do
12
12
 
13
13
  # for env, see bottom of file - it's long
14
14
  let(:operation) { BatchApi::Operation::Rack.new(op_params, env, app) }
15
- let(:app) { stub("application", call: [200, {}, ["foo"]]) }
15
+ let(:app) { double("application", call: [200, {}, ["foo"]]) }
16
16
 
17
17
  describe "accessors" do
18
18
  [
@@ -21,9 +21,9 @@ describe BatchApi::Operation::Rack do
21
21
  ].each do |a|
22
22
  attr = a
23
23
  it "has an accessor for #{attr}" do
24
- value = stub
24
+ value = double
25
25
  operation.send("#{attr}=", value)
26
- operation.send(attr).should == value
26
+ expect(operation.send(attr)).to eq(value)
27
27
  end
28
28
  end
29
29
  end
@@ -32,38 +32,38 @@ describe BatchApi::Operation::Rack do
32
32
  ["method", "url", "params", "headers"].each do |a|
33
33
  attr = a
34
34
  it "extracts the #{attr} information from the operation params" do
35
- operation.send(attr).should == op_params[attr]
35
+ expect(operation.send(attr)).to eq(op_params[attr])
36
36
  end
37
37
  end
38
38
 
39
39
  it "sets options to the op" do
40
- operation.options.should == op_params
40
+ expect(operation.options).to eq(op_params)
41
41
  end
42
42
 
43
43
  it "defaults method to get if not provided" do
44
44
  op = BatchApi::Operation::Rack.new(op_params.except("method"), env, app)
45
- op.method.should == "get"
45
+ expect(op.method).to eq("get")
46
46
  end
47
47
 
48
48
  it "defaults params to {} if not provided" do
49
49
  op = BatchApi::Operation::Rack.new(op_params.except("params"), env, app)
50
- op.params.should == {}
50
+ expect(op.params).to eq({})
51
51
  end
52
52
 
53
53
  it "defaults headers to {} if not provided" do
54
54
  op = BatchApi::Operation::Rack.new(op_params.except("headers"), env, app)
55
- op.headers.should == {}
55
+ expect(op.headers).to eq({})
56
56
  end
57
57
 
58
58
  it "does a deep dup of the env" do
59
- operation.env.should == env
59
+ expect(operation.env).to eq(env)
60
60
 
61
61
  flat_env = env.to_a.flatten
62
62
  operation.env.to_a.flatten.each_with_index do |obj, index|
63
63
  # this is a rough test for deep dup -- make sure the objects
64
64
  # that aren't symbols aren't actually the same objects in memory
65
65
  if obj.is_a?(Hash) || obj.is_a?(Array)
66
- obj.object_id.should_not == flat_env[index].object_id
66
+ expect(obj.object_id).not_to eq(flat_env[index].object_id)
67
67
  end
68
68
  end
69
69
  end
@@ -79,64 +79,72 @@ describe BatchApi::Operation::Rack do
79
79
  describe "#process_env" do
80
80
  let(:processed_env) { operation.tap {|o| o.process_env}.env }
81
81
 
82
+ before { BatchApi.config.stub(endpoint: '/api/batch') }
83
+
82
84
  it "merges any headers in in the right format" do
83
85
  key = "HTTP_FOO" # as defined above in op_params
84
86
 
85
- processed_env[key].should_not == env[key]
87
+ expect(processed_env[key]).not_to eq(env[key])
86
88
  # in this case, it's a batch controller
87
- processed_env[key].should == op_params["headers"]["foo"]
89
+ expect(processed_env[key]).to eq(op_params["headers"]["foo"])
88
90
  end
89
91
 
90
92
  it "preserves existing headers" do
91
- processed_env["HTTP_PREVIOUS_HEADERS"].should == env["HTTP_PREVIOUS_HEADERS"]
93
+ expect(processed_env["HTTP_PREVIOUS_HEADERS"]).to eq(env["HTTP_PREVIOUS_HEADERS"])
92
94
  end
93
95
 
94
96
  it "updates the method" do
95
97
  key = "REQUEST_METHOD"
96
- processed_env[key].should_not == env[key]
97
- processed_env[key].should == "POST"
98
+ expect(processed_env[key]).not_to eq(env[key])
99
+ expect(processed_env[key]).to eq("POST")
98
100
  end
99
101
 
100
102
  it "updates the REQUEST_URI" do
101
103
  key = "REQUEST_URI"
102
- processed_env[key].should_not == env[key]
103
- processed_env[key].should == env["REQUEST_URI"].gsub(/\/batch.*/, op_params["url"])
104
+ expect(processed_env[key]).not_to eq(env[key])
105
+ expect(processed_env[key]).to eq("http://localhost:3000#{op_params["url"]}")
106
+ end
107
+
108
+ it "works if REQUEST_URI is blank" do
109
+ key = "REQUEST_URI"
110
+ env.delete(key)
111
+ expect(processed_env[key]).to be_nil
104
112
  end
105
113
 
106
114
  it "updates the REQUEST_PATH with the path component (w/o params)" do
107
115
  key = "REQUEST_PATH"
108
- processed_env[key].should_not == env[key]
109
- processed_env[key].should == op_params["url"].split("?").first
116
+ expect(processed_env[key]).not_to eq(env[key])
117
+ expect(processed_env[key]).to eq(op_params["url"].split("?").first)
110
118
  end
111
119
 
112
120
  it "updates the original fullpath" do
113
121
  key = "ORIGINAL_FULLPATH"
114
- processed_env[key].should_not == env[key]
115
- processed_env[key].should == op_params["url"]
122
+ expect(processed_env[key]).not_to eq(env[key])
123
+ expect(processed_env[key]).to eq(op_params["url"])
116
124
  end
117
125
 
118
126
  it "updates the PATH_INFO" do
119
127
  key = "PATH_INFO"
120
- processed_env[key].should_not == env[key]
121
- processed_env[key].should == op_params["url"]
128
+ expect(processed_env[key]).not_to eq(env[key])
129
+ expect(processed_env[key]).to eq(op_params["url"])
122
130
  end
123
131
 
124
132
  it "updates the rack query string" do
125
133
  key = "rack.request.query_string"
126
- processed_env[key].should_not == env[key]
127
- processed_env[key].should == op_params["url"].split("?").last
134
+ expect(processed_env[key]).not_to eq(env[key])
135
+ expect(processed_env[key]).to eq(op_params["url"].split("?").last)
128
136
  end
129
137
 
130
138
  it "updates the QUERY_STRING" do
131
139
  key = "QUERY_STRING"
132
- processed_env[key].should_not == env[key]
133
- processed_env[key].should == op_params["url"].split("?").last
140
+ expect(processed_env[key]).not_to eq(env[key])
141
+ expect(processed_env[key]).to eq(op_params["url"].split("?").last)
134
142
  end
135
143
 
136
144
  it "updates the form hash" do
137
145
  key = "rack.request.form_hash"
138
- processed_env[key].should_not == env[key]
139
- processed_env[key].should == op_params["params"]
146
+ expect(processed_env[key]).not_to eq(env[key])
147
+ expect(processed_env[key]).to eq(op_params["params"])
140
148
  end
141
149
 
142
150
  context "query_hash" do
@@ -144,14 +152,14 @@ describe BatchApi::Operation::Rack do
144
152
  operation.method = "get"
145
153
  processed_env = operation.tap {|o| o.process_env}.env
146
154
  key = "rack.request.query_hash"
147
- processed_env[key].should_not == env[key]
148
- processed_env[key].should == op_params["params"]
155
+ expect(processed_env[key]).not_to eq(env[key])
156
+ expect(processed_env[key]).to eq(op_params["params"])
149
157
  end
150
158
 
151
159
  it "sets it to nil for a POST" do
152
160
  key = "rack.request.query_hash"
153
- processed_env[key].should_not == env[key]
154
- processed_env[key].should be_nil
161
+ expect(processed_env[key]).not_to eq(env[key])
162
+ expect(processed_env[key]).to be_nil
155
163
  end
156
164
  end
157
165
  end
@@ -161,39 +169,39 @@ describe BatchApi::Operation::Rack do
161
169
  let(:result) { [
162
170
  200,
163
171
  {header: "footer"},
164
- stub(body: "{\"data\":2}", cookies: nil)
172
+ double(body: "{\"data\":2}", cookies: nil)
165
173
  ] }
166
- let(:processed_env) { stub }
174
+ let(:processed_env) { double }
167
175
 
168
176
  before :each do
169
- operation.stub(:process_env) { operation.env = processed_env }
177
+ allow(operation).to receive(:process_env) { operation.env = processed_env }
170
178
  end
171
179
 
172
180
  it "executes the call with the application" do
173
- app.should_receive(:call).with(processed_env)
181
+ expect(app).to receive(:call).with(processed_env)
174
182
  operation.execute
175
183
  end
176
184
 
177
185
  it "returns a BatchAPI::Response made from the result" do
178
- response = stub
179
- app.stub(:call).and_return(result)
180
- BatchApi::Response.should_receive(:new).with(result).and_return(response)
181
- operation.execute.should == response
186
+ response = double
187
+ allow(app).to receive(:call).and_return(result)
188
+ expect(BatchApi::Response).to receive(:new).with(result).and_return(response)
189
+ expect(operation.execute).to eq(response)
182
190
  end
183
191
 
184
192
  it "returns a BatchApi::Response from an ErrorWrapper for errors" do
185
193
  err = StandardError.new
186
- result, rendered, response = stub, stub, stub
187
- b_err = stub("batch error", render: rendered)
194
+ result, rendered, response = double, double, double
195
+ b_err = double("batch error", render: rendered)
188
196
 
189
197
  # simulate the error
190
- app.stub(:call).and_raise(err)
198
+ allow(app).to receive(:call).and_raise(err)
191
199
  # we'll create the BatchError
192
- BatchApi::ErrorWrapper.should_receive(:new).with(err).and_return(b_err)
200
+ expect(BatchApi::ErrorWrapper).to receive(:new).with(err).and_return(b_err)
193
201
  # render that as the response
194
- BatchApi::Response.should_receive(:new).with(rendered).and_return(response)
202
+ expect(BatchApi::Response).to receive(:new).with(rendered).and_return(response)
195
203
  # and return the response overall
196
- operation.execute.should == response
204
+ expect(operation.execute).to eq(response)
197
205
  end
198
206
  end
199
207
  end
@@ -208,7 +216,7 @@ describe BatchApi::Operation::Rack do
208
216
  "REMOTE_ADDR"=>"127.0.0.1",
209
217
  "REMOTE_HOST"=>"1035.spotilocal.com",
210
218
  "REQUEST_METHOD"=>"REPORT",
211
- "REQUEST_URI"=>"http://localhost:3000/batch",
219
+ "REQUEST_URI"=>"http://localhost:3000/api/batch",
212
220
  "SCRIPT_NAME"=>"",
213
221
  "SERVER_NAME"=>"localhost",
214
222
  "SERVER_PORT"=>"3000",
@@ -226,8 +234,8 @@ describe BatchApi::Operation::Rack do
226
234
  "rack.run_once"=>false,
227
235
  "rack.url_scheme"=>"http",
228
236
  "HTTP_VERSION"=>"HTTP/1.1",
229
- "REQUEST_PATH"=>"/batch",
230
- "ORIGINAL_FULLPATH"=>"/batch",
237
+ "REQUEST_PATH"=>"/api/batch",
238
+ "ORIGINAL_FULLPATH"=>"/api/batch",
231
239
  "rack.request.form_input"=>StringIO.new("{\"ops\":{}}"),
232
240
  "rack.request.form_hash"=>{"{\"ops\":{}}"=>nil},
233
241
  "rack.request.form_vars"=>"{\"ops\":{}}",