Skip to content

Commit

Permalink
Merge pull request #273 from dmathieu/rspec_mock
Browse files Browse the repository at this point in the history
Use rspec-mocks instead of rr
  • Loading branch information
gudmundur authored Jun 10, 2016
2 parents 514400f + 3fcc270 commit f1ff6ed
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 31 deletions.
1 change: 0 additions & 1 deletion pliny.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Gem::Specification.new do |gem|

gem.add_development_dependency "rake", "~> 0.8", ">= 0.8.7"
gem.add_development_dependency "rack-test", "~> 0.6", ">= 0.6.2"
gem.add_development_dependency "rr", "~> 1.1", ">= 1.1.2"
gem.add_development_dependency "rspec", "~> 3.1", ">= 3.1.0"
gem.add_development_dependency "sinatra-contrib", "~> 1.4", ">= 1.4.7"
gem.add_development_dependency "timecop", "~> 0.7", ">= 0.7.1"
Expand Down
4 changes: 1 addition & 3 deletions spec/commands/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
before do
Timecop.freeze(@t = Time.now)

any_instance_of(Pliny::Commands::Generator::Base) do |klass|
stub(klass).display
end
allow_any_instance_of(Pliny::Commands::Generator::Base).to receive(:display)
end

around do |example|
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@io = StringIO.new
@cmd = Pliny::Commands::Updater.new(@io)

stub(@cmd).exec_patch
allow(@cmd).to receive(:exec_patch)
end

describe "#run!" do
Expand Down
6 changes: 3 additions & 3 deletions spec/error_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
end

it "notifies rollbar" do
any_instance_of(Pliny::ErrorReporter::RollbarReporter) do |klass|
stub(klass).notify(exception, context: context, rack_env: rack_env)
end
expect_any_instance_of(Pliny::ErrorReporter::RollbarReporter).
to receive(:notify).
with(exception, context: context, rack_env: rack_env)

notify_reporter
end
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def app
end

before do
stub(Config).pretty_json { false }
allow(Config).to receive(:pretty_json) { false }
end

it "sets the Content-Type" do
Expand All @@ -33,7 +33,7 @@ def app
end

it "encodes in pretty mode when set by config" do
stub(Config).pretty_json { true }
allow(Config).to receive(:pretty_json) { true }
payload = { "foo" => "bar" }
post "/", payload
assert_equal MultiJson.encode(payload, pretty: true), last_response.body
Expand Down
22 changes: 11 additions & 11 deletions spec/log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
@io = StringIO.new
Pliny.stdout = @io
Pliny.stderr = @io
stub(@io).print
allow(@io).to receive(:print)
end

after do
Pliny.default_context = {}
end

it "logs in structured format" do
mock(@io).print "foo=bar baz=42\n"
expect(@io).to receive(:print).with("foo=bar baz=42\n")
Pliny.log(foo: "bar", baz: 42)
end

Expand All @@ -26,41 +26,41 @@
end

it "supports blocks to log stages and elapsed" do
mock(@io).print "foo=bar at=start\n"
mock(@io).print "foo=bar at=finish elapsed=0.000\n"
expect(@io).to receive(:print).with("foo=bar at=start\n")
expect(@io).to receive(:print).with("foo=bar at=finish elapsed=0.000\n")
Pliny.log(foo: "bar") do
end
end

it "merges default context" do
Pliny.default_context = { app: "pliny" }
mock(@io).print "app=pliny foo=bar\n"
expect(@io).to receive(:print).with("app=pliny foo=bar\n")
Pliny.log(foo: "bar")
end

it "merges context from RequestStore" do
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
mock(@io).print "app=pliny foo=bar\n"
expect(@io).to receive(:print).with("app=pliny foo=bar\n")
Pliny.log(foo: "bar")
end

it "supports a context" do
mock(@io).print "app=pliny foo=bar\n"
expect(@io).to receive(:print).with("app=pliny foo=bar\n")
Pliny.context(app: "pliny") do
Pliny.log(foo: "bar")
end
end

it "local context does not overwrite default context" do
Pliny.default_context = { app: "pliny" }
mock(@io).print "app=not_pliny foo=bar\n"
expect(@io).to receive(:print).with("app=not_pliny foo=bar\n")
Pliny.log(app: 'not_pliny', foo: "bar")
assert Pliny.default_context[:app] == "pliny"
end

it "local context does not overwrite request context" do
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
mock(@io).print "app=not_pliny foo=bar\n"
expect(@io).to receive(:print).with("app=not_pliny foo=bar\n")
Pliny.context(app: "not_pliny") do
Pliny.log(foo: "bar")
end
Expand All @@ -69,7 +69,7 @@

it "local context does not propagate outside" do
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
mock(@io).print "app=pliny foo=bar\n"
expect(@io).to receive(:print).with("app=pliny foo=bar\n")
Pliny.context(app: "not_pliny", test: 123) do
end
Pliny.log(foo: "bar")
Expand All @@ -78,7 +78,7 @@
it "logs exceptions" do
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
e = RuntimeError.new
mock(@io).print "app=pliny exception class=RuntimeError message=RuntimeError exception_id=#{e.object_id}\n"
expect(@io).to receive(:print).with("app=pliny exception class=RuntimeError message=RuntimeError exception_id=#{e.object_id}\n")
Pliny.log_exception(e)
end
end
8 changes: 4 additions & 4 deletions spec/middleware/instruments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def app
end

it "performs logging" do
mock(Pliny).log(hash_including(
expect(Pliny).to receive(:log).with(hash_including(
instrumentation: true,
at: "start",
method: "GET",
path: "/apps/123",
))
mock(Pliny).log(hash_including(
expect(Pliny).to receive(:log).with(hash_including(
instrumentation: true,
at: "finish",
method: "GET",
Expand All @@ -41,8 +41,8 @@ def app
end

it "respects Pliny error status codes" do
mock(Pliny).log.with_any_args
mock(Pliny).log(hash_including(
expect(Pliny).to receive(:log)
expect(Pliny).to receive(:log).with(hash_including(
status: 404
))
get "/error"
Expand Down
4 changes: 2 additions & 2 deletions spec/middleware/request_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def app
end

it "clears the store" do
mock(Pliny::RequestStore).clear!
expect(Pliny::RequestStore).to receive(:clear!)
get "/"
end

it "seeds the store" do
mock(Pliny::RequestStore).seed.with_any_args
expect(Pliny::RequestStore).to receive(:seed)
get "/"
end
end
2 changes: 1 addition & 1 deletion spec/middleware/rescue_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def app

it "intercepts exceptions and renders" do
@app = new_rack_app
mock(Pliny::ErrorReporter).notify.with_any_args
expect(Pliny::ErrorReporter).to receive(:notify)
get "/"
assert_equal 500, last_response.status
error_json = MultiJson.decode(last_response.body)
Expand Down
1 change: 0 additions & 1 deletion spec/middleware/versioning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
before do
@io = StringIO.new
Pliny.stdout = @io
stub(@io).print
end

def app
Expand Down
2 changes: 1 addition & 1 deletion spec/rollbar_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:log_context) { { rollbar: true, level: level, message: message } }

before do
mock(Pliny).log(log_context)
expect(Pliny).to receive(:log).with(log_context)
end

context '#debug' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
config.include Rack::Test::Methods

config.expect_with :minitest
config.mock_with :rr
config.mock_with :rspec
config.run_all_when_everything_filtered = true
config.filter_run :focus

Expand Down

0 comments on commit f1ff6ed

Please sign in to comment.