From 3fcc2709e6fb9229354e5f712665998c8e526ba4 Mon Sep 17 00:00:00 2001 From: Damien Mathieu Date: Wed, 1 Jun 2016 10:56:29 +0200 Subject: [PATCH] use rspec-mocks instead of rr --- pliny.gemspec | 1 - spec/commands/generator_spec.rb | 4 +--- spec/commands/updater_spec.rb | 2 +- spec/error_reporter_spec.rb | 6 +++--- spec/helpers/encode_spec.rb | 4 ++-- spec/log_spec.rb | 22 +++++++++++----------- spec/middleware/instruments_spec.rb | 8 ++++---- spec/middleware/request_store_spec.rb | 4 ++-- spec/middleware/rescue_errors_spec.rb | 2 +- spec/middleware/versioning_spec.rb | 1 - spec/rollbar_logger_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 12 files changed, 27 insertions(+), 31 deletions(-) diff --git a/pliny.gemspec b/pliny.gemspec index 27fa42fc..ed925873 100644 --- a/pliny.gemspec +++ b/pliny.gemspec @@ -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" diff --git a/spec/commands/generator_spec.rb b/spec/commands/generator_spec.rb index 72d73acd..fffeb398 100644 --- a/spec/commands/generator_spec.rb +++ b/spec/commands/generator_spec.rb @@ -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| diff --git a/spec/commands/updater_spec.rb b/spec/commands/updater_spec.rb index e2aac789..0bb8ed01 100644 --- a/spec/commands/updater_spec.rb +++ b/spec/commands/updater_spec.rb @@ -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 diff --git a/spec/error_reporter_spec.rb b/spec/error_reporter_spec.rb index 9f963171..0f7f73cf 100644 --- a/spec/error_reporter_spec.rb +++ b/spec/error_reporter_spec.rb @@ -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 diff --git a/spec/helpers/encode_spec.rb b/spec/helpers/encode_spec.rb index 7ef1100f..ee0ee028 100644 --- a/spec/helpers/encode_spec.rb +++ b/spec/helpers/encode_spec.rb @@ -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 @@ -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 diff --git a/spec/log_spec.rb b/spec/log_spec.rb index 76123c61..3caa6f35 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -5,7 +5,7 @@ @io = StringIO.new Pliny.stdout = @io Pliny.stderr = @io - stub(@io).print + allow(@io).to receive(:print) end after do @@ -13,7 +13,7 @@ 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 @@ -26,26 +26,26 @@ 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 @@ -53,14 +53,14 @@ 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 @@ -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") @@ -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 diff --git a/spec/middleware/instruments_spec.rb b/spec/middleware/instruments_spec.rb index ac54fdf7..8a3626d9 100644 --- a/spec/middleware/instruments_spec.rb +++ b/spec/middleware/instruments_spec.rb @@ -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", @@ -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" diff --git a/spec/middleware/request_store_spec.rb b/spec/middleware/request_store_spec.rb index 06f4acfb..16597afb 100644 --- a/spec/middleware/request_store_spec.rb +++ b/spec/middleware/request_store_spec.rb @@ -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 diff --git a/spec/middleware/rescue_errors_spec.rb b/spec/middleware/rescue_errors_spec.rb index 43d2e472..8bd94845 100644 --- a/spec/middleware/rescue_errors_spec.rb +++ b/spec/middleware/rescue_errors_spec.rb @@ -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) diff --git a/spec/middleware/versioning_spec.rb b/spec/middleware/versioning_spec.rb index 517ebcf2..da2cbea3 100644 --- a/spec/middleware/versioning_spec.rb +++ b/spec/middleware/versioning_spec.rb @@ -5,7 +5,6 @@ before do @io = StringIO.new Pliny.stdout = @io - stub(@io).print end def app diff --git a/spec/rollbar_logger_spec.rb b/spec/rollbar_logger_spec.rb index 4ef4c07e..340b5251 100644 --- a/spec/rollbar_logger_spec.rb +++ b/spec/rollbar_logger_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 586376b2..1ba5e46d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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