Skip to content

Commit

Permalink
Use transpec to update specs.
Browse files Browse the repository at this point in the history
92 conversions
  from: obj.should
    to: expect(obj).to
90 conversions
  from: == expected
    to: eq(expected)
42 conversions
  from: stub('something')
    to: double('something')
28 conversions
  from: obj.stub(:message)
    to: allow(obj).to receive(:message)
18 conversions
  from: obj.should_not
    to: expect(obj).not_to
13 conversions
  from: obj.should_receive(:message)
    to: expect(obj).to receive(:message)
1 conversion
  from: be_false
    to: be_falsey
1 conversion
  from: be_true
    to: be_truthy
1 addition
    of: RSpec.configure { |c| c.infer_spec_type_from_file_location! }
  • Loading branch information
arsduo committed Apr 6, 2015
1 parent 8c22c6c commit 41c0c89
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 190 deletions.
6 changes: 3 additions & 3 deletions spec/lib/batch_api_spec.rb
Expand Up @@ -4,17 +4,17 @@
describe BatchApi do
describe ".config" do
it "has a reader for config" do
BatchApi.config.should_not be_nil
expect(BatchApi.config).not_to be_nil
end

it "provides a default config" do
BatchApi.config.should be_a(BatchApi::Configuration)
expect(BatchApi.config).to be_a(BatchApi::Configuration)
end
end

describe ".rails?" do
it "returns a value we can't test based on whether Rails is defined" do
BatchApi.rails?.should_not be_nil
expect(BatchApi.rails?).not_to be_nil
end
end
end
6 changes: 3 additions & 3 deletions spec/lib/batch_error_spec.rb
Expand Up @@ -9,15 +9,15 @@
BatchApi::Errors::MalformedOperationError
].each do |klass|
it "provides a #{klass} error based on ArgumentError" do
klass.superclass.should == ArgumentError
expect(klass.superclass).to eq(ArgumentError)
end

it "is is also a BatchError" do
klass.new.should be_a(BatchApi::Errors::BatchError)
expect(klass.new).to be_a(BatchApi::Errors::BatchError)
end

it "has a status code of 422" do
klass.new.status_code.should == 422
expect(klass.new.status_code).to eq(422)
end
end
end
6 changes: 3 additions & 3 deletions spec/lib/configuration_spec.rb
Expand Up @@ -15,13 +15,13 @@ module BatchApi
opt, defa = option, default
describe "##{opt}" do
it "has an accessor for #{opt}" do
stubby = stub
stubby = double
config.send("#{opt}=", stubby)
config.send(opt).should == stubby
expect(config.send(opt)).to eq(stubby)
end

it "defaults #{opt} to #{defa.inspect}" do
config.send(opt).should == defa
expect(config.send(opt)).to eq(defa)
end
end
end
Expand Down
40 changes: 20 additions & 20 deletions spec/lib/error_wrapper_spec.rb
Expand Up @@ -12,57 +12,57 @@

describe "#body" do
it "includes the message in the body" do
error.body[:error][:message].should == exception.message
expect(error.body[:error][:message]).to eq(exception.message)
end

it "includes the backtrace if it should be there" do
error.stub(:expose_backtrace?).and_return(true)
error.body[:error][:backtrace].should == exception.backtrace
allow(error).to receive(:expose_backtrace?).and_return(true)
expect(error.body[:error][:backtrace]).to eq(exception.backtrace)
end

it "includes the backtrace if it should be there" do
error.stub(:expose_backtrace?).and_return(false)
error.body[:backtrace].should be_nil
allow(error).to receive(:expose_backtrace?).and_return(false)
expect(error.body[:backtrace]).to be_nil
end
end

describe "#render" do
it "returns the appropriate status" do
status = stub
error.stub(:status_code).and_return(status)
error.render[0].should == status
status = double
allow(error).to receive(:status_code).and_return(status)
expect(error.render[0]).to eq(status)
end

it "returns appropriate content type" do
ctype = stub
BatchApi::RackMiddleware.stub(:content_type).and_return(ctype)
error.render[1].should == ctype
ctype = double
allow(BatchApi::RackMiddleware).to receive(:content_type).and_return(ctype)
expect(error.render[1]).to eq(ctype)
end

it "returns the JSONified body as the 2nd" do
error.render[2].should == [MultiJson.dump(error.body)]
expect(error.render[2]).to eq([MultiJson.dump(error.body)])
end
end

describe "#status_code" do
it "returns 500 by default" do
error.status_code.should == 500
expect(error.status_code).to eq(500)
end

it "returns another status code if the error supports that" do
err = StandardError.new
code = stub
err.stub(:status_code).and_return(code)
BatchApi::ErrorWrapper.new(err).status_code.should == code
code = double
allow(err).to receive(:status_code).and_return(code)
expect(BatchApi::ErrorWrapper.new(err).status_code).to eq(code)
end
end

describe ".expose_backtrace?" do
it "returns false if Rails.env.production?" do
Rails.stub(:env).and_return(double(test?: false, production?: true, development?: false))
BatchApi::ErrorWrapper.expose_backtrace?.should be_false
Rails.env.stub(:production?).and_return(false)
BatchApi::ErrorWrapper.expose_backtrace?.should be_true
allow(Rails).to receive(:env).and_return(double(test?: false, production?: true, development?: false))
expect(BatchApi::ErrorWrapper.expose_backtrace?).to be_falsey
allow(Rails.env).to receive(:production?).and_return(false)
expect(BatchApi::ErrorWrapper.expose_backtrace?).to be_truthy
end
end
end
14 changes: 7 additions & 7 deletions spec/lib/internal_middleware/decode_json_body_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'

describe BatchApi::InternalMiddleware::DecodeJsonBody do
let(:app) { stub("app", call: result) }
let(:app) { double("app", call: result) }
let(:decoder) { BatchApi::InternalMiddleware::DecodeJsonBody.new(app) }
let(:env) { stub("env") }
let(:env) { double("env") }
let(:json) { {"data" => "is_json", "more" => {"hi" => "there"} } }
let(:result) {
BatchApi::Response.new([
Expand All @@ -17,27 +17,27 @@
context "for json results" do
it "decodes JSON results for application/json responses" do
result = decoder.call(env)
result.body.should == json
expect(result.body).to eq(json)
end

it "doesn't change anything else" do
result = decoder.call(env)
result.status.should == 200
result.headers.should == {"Content-Type" => "application/json"}
expect(result.status).to eq(200)
expect(result.headers).to eq({"Content-Type" => "application/json"})
end
end

context "for non-JSON responses" do
it "doesn't decode" do
result.headers = {"Content-Type" => "text/html"}
decoder.call(env).body.should == MultiJson.dump(json)
expect(decoder.call(env).body).to eq(MultiJson.dump(json))
end
end

context "for empty responses" do
it "doesn't try to parse" do
result.body = ""
decoder.call(env).body.should == ""
expect(decoder.call(env).body).to eq("")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/internal_middleware/response_filter_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'

describe BatchApi::InternalMiddleware::ResponseFilter do
let(:app) { stub("app", call: result) }
let(:app) { double("app", call: result) }
let(:surpressor) { BatchApi::InternalMiddleware::ResponseFilter.new(app) }
let(:env) { {
op: stub("operation", options: {"silent" => true})
op: double("operation", options: {"silent" => true})
} }

let(:result) {
Expand All @@ -20,7 +20,7 @@
context "for successful (200-299) results" do
it "empties the response so its as_json is empty" do
surpressor.call(env)
result.as_json.should == {}
expect(result.as_json).to eq({})
end
end

Expand Down
28 changes: 15 additions & 13 deletions spec/lib/internal_middleware_spec.rb
Expand Up @@ -20,7 +20,7 @@ def use(middleware, *args)
builder.instance_eval(
&BatchApi::InternalMiddleware::DEFAULT_BATCH_MIDDLEWARE
)
builder.middlewares.should be_empty
expect(builder.middlewares).to be_empty
end

describe "internal middleware defaults" do
Expand All @@ -31,38 +31,40 @@ def use(middleware, *args)
end

it "builds a per-op middleware with the response silencer" do
builder.middlewares[0].should ==
expect(builder.middlewares[0]).to eq(
[BatchApi::InternalMiddleware::ResponseFilter, []]
)
end

it "builds a per-op middleware with the JSON decoder" do
builder.middlewares[1].should ==
expect(builder.middlewares[1]).to eq(
[BatchApi::InternalMiddleware::DecodeJsonBody, []]
)
end
end

describe ".batch_stack" do
# we can't use stubs inside the procs since they're instance_eval'd
let(:global_config) { Proc.new { use "Global" } }
let(:strategy) { stub("strategy") }
let(:processor) { stub("processor", strategy: strategy) }
let(:strategy) { double("strategy") }
let(:processor) { double("processor", strategy: strategy) }
let(:stack) { BatchApi::InternalMiddleware.batch_stack(processor) }

before :each do
BatchApi.config.stub(:batch_middleware).and_return(global_config)
allow(BatchApi.config).to receive(:batch_middleware).and_return(global_config)
stub_const("Middleware::Builder", FakeBuilder)
end

it "builds the stack with the right number of wares" do
stack.middlewares.length.should == 2
expect(stack.middlewares.length).to eq(2)
end

it "builds a middleware stack starting with the configured global wares" do
stack.middlewares[0].first.should == "Global"
expect(stack.middlewares[0].first).to eq("Global")
end

it "inserts the appropriate strategy from the processor" do
stack.middlewares[1].first.should == strategy
expect(stack.middlewares[1].first).to eq(strategy)
end
end

Expand All @@ -72,20 +74,20 @@ def use(middleware, *args)
let(:stack) { BatchApi::InternalMiddleware.operation_stack }

before :each do
BatchApi.config.stub(:operation_middleware).and_return(op_config)
allow(BatchApi.config).to receive(:operation_middleware).and_return(op_config)
stub_const("Middleware::Builder", FakeBuilder)
end

it "builds the stack with the right number of wares" do
stack.middlewares.length.should == 2
expect(stack.middlewares.length).to eq(2)
end

it "builds a middleware stack including the configured per-op wares" do
stack.middlewares[0].first.should == "Op"
expect(stack.middlewares[0].first).to eq("Op")
end

it "builds a middleware stack ending with the executor" do
stack.middlewares[1].first.should == BatchApi::Processor::Executor
expect(stack.middlewares[1].first).to eq(BatchApi::Processor::Executor)
end
end
end

0 comments on commit 41c0c89

Please sign in to comment.