From 96e30031b275acddaf7c7938cf38cfa8a823dc38 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Tue, 23 Sep 2014 21:01:40 +0200 Subject: [PATCH] Actually use spec_helper, lol --- spec/decorators/asciicast_decorator_spec.rb | 8 ++++++++ spec/decorators/user_decorator_spec.rb | 16 ++++++++++++++++ spec/presenters/asciicast_page_presenter_spec.rb | 7 ++----- spec/presenters/user_page_presenter_spec.rb | 2 +- spec/rails_helper.rb | 5 ++++- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/spec/decorators/asciicast_decorator_spec.rb b/spec/decorators/asciicast_decorator_spec.rb index edafc31..17f8292 100644 --- a/spec/decorators/asciicast_decorator_spec.rb +++ b/spec/decorators/asciicast_decorator_spec.rb @@ -176,6 +176,14 @@ describe AsciicastDecorator do let(:snapshot) { double('snapshot', :thumbnail => thumbnail) } let(:thumbnail) { double('thumbnail') } + before do + RSpec::Mocks.configuration.verify_partial_doubles = false # for stubbing "helpers" + end + + after do + RSpec::Mocks.configuration.verify_partial_doubles = true + end + before do allow(asciicast).to receive(:snapshot) { json } allow(Snapshot).to receive(:build).with(json) { snapshot } diff --git a/spec/decorators/user_decorator_spec.rb b/spec/decorators/user_decorator_spec.rb index abef228..c9a410c 100644 --- a/spec/decorators/user_decorator_spec.rb +++ b/spec/decorators/user_decorator_spec.rb @@ -9,10 +9,18 @@ describe UserDecorator do let(:user) { User.new(username: 'satyr') } + before do + RSpec::Mocks.configuration.verify_partial_doubles = false # for stubbing "h" + end + before do allow(h).to receive(:profile_path).with(user) { '/path' } end + after do + RSpec::Mocks.configuration.verify_partial_doubles = true + end + context "when user is real" do before do user.dummy = false @@ -39,11 +47,19 @@ describe UserDecorator do let(:user) { User.new(username: 'satyr') } + before do + RSpec::Mocks.configuration.verify_partial_doubles = false # for stubbing "h" + end + before do allow(h).to receive(:profile_path).with(user) { '/path' } allow(decorator).to receive(:avatar_image_tag) { ''.html_safe } end + after do + RSpec::Mocks.configuration.verify_partial_doubles = true + end + context "when user is real" do before do user.dummy = false diff --git a/spec/presenters/asciicast_page_presenter_spec.rb b/spec/presenters/asciicast_page_presenter_spec.rb index 8cca0ea..fe15342 100644 --- a/spec/presenters/asciicast_page_presenter_spec.rb +++ b/spec/presenters/asciicast_page_presenter_spec.rb @@ -25,7 +25,7 @@ describe AsciicastPagePresenter do end let(:presenter) { described_class.new(asciicast, current_user, policy, nil) } - let(:asciicast) { stub_model(Asciicast, user: author) } + let(:asciicast) { stub_model(Asciicast, user: author).decorate } let(:current_user) { User.new } let(:policy) { double('policy') } let(:author) { User.new } @@ -113,16 +113,13 @@ describe AsciicastPagePresenter do describe '#embed_script' do subject { presenter.embed_script(view_context) } + let(:asciicast) { stub_model(Asciicast, id: 123).decorate } let(:src_regexp) { /src="[^"]+\b123\b[^"]*\.js"/ } let(:id_regexp) { /id="asciicast-123"/ } let(:script_regexp) { /^]+#{src_regexp}[^>]+#{id_regexp}[^>]*><\/script>/ } - before do - allow(asciicast).to receive(:id).and_return(123) - end - it 'is an async script tag including asciicast id' do expect(subject).to match(script_regexp) end diff --git a/spec/presenters/user_page_presenter_spec.rb b/spec/presenters/user_page_presenter_spec.rb index f14724c..7bae402 100644 --- a/spec/presenters/user_page_presenter_spec.rb +++ b/spec/presenters/user_page_presenter_spec.rb @@ -46,7 +46,7 @@ describe UserPagePresenter do let(:presenter) { described_class.new(user, current_user, policy, page, per_page) } - let(:user) { stub_model(User, username: 'cartman') } + let(:user) { stub_model(User, username: 'cartman').decorate } let(:current_user) { stub_model(User) } let(:policy) { double('policy') } let(:page) { 2 } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3df3c98..a1abb97 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,3 +1,7 @@ +ENV["RAILS_ENV"] ||= 'test' + +require 'spec_helper' + if ENV["CI"] && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") require 'simplecov' require 'coveralls' @@ -9,7 +13,6 @@ if ENV["CI"] && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") end end -ENV["RAILS_ENV"] ||= 'test' ENV['CARRIERWAVE_STORAGE_DIR_PREFIX'] ||= 'uploads/test/' require File.expand_path("../../config/environment", __FILE__)