Skip to content

Commit

Permalink
Update to rspec 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jul 17, 2014
1 parent 9b0626b commit d3c7955
Show file tree
Hide file tree
Showing 44 changed files with 515 additions and 515 deletions.
2 changes: 1 addition & 1 deletion app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def should_autofocus_on_search_box?
# @param [SolrDocument]
# @return [Boolean]
def has_thumbnail? document
blacklight_config.view_config(document_index_view_type).thumbnail_method or
blacklight_config.view_config(document_index_view_type).thumbnail_method.present? or
blacklight_config.view_config(document_index_view_type).thumbnail_field && document.has?(blacklight_config.view_config(document_index_view_type).thumbnail_field)
end

Expand Down
3 changes: 2 additions & 1 deletion blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ Gem::Specification.new do |s|

s.add_development_dependency "jettywrapper", ">= 1.7.0"
s.add_development_dependency "blacklight-marc", "~> 5.0"
s.add_development_dependency "rspec-rails", "~> 2.99"
s.add_development_dependency "rspec-rails", "~> 3.0"
s.add_development_dependency "rspec-its"
s.add_development_dependency "rspec-collection_matchers", ">= 1.0"
s.add_development_dependency "capybara"
s.add_development_dependency "poltergeist"
s.add_development_dependency 'engine_cart', ">= 0.1.0"
Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/bookmarks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
end

it "has a 500 status code when fails is success" do
@controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
@controller.stub_chain(:current_or_guest_user, :persisted?).and_return(true)
@controller.stub_chain(:current_or_guest_user, :bookmarks, :where, :exists?).and_return(false)
@controller.stub_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
allow(@controller).to receive_message_chain(:current_or_guest_user, :persisted?).and_return(true)
allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :exists?).and_return(false)
allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
xhr :put, :update, :id => 'iamabooboo', :format => :js
expect(response.code).to eq "500"
end
Expand All @@ -33,8 +33,8 @@

it "has a 500 status code when delete is not success" do
bm = double(Bookmark)
@controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
@controller.stub_chain(:current_or_guest_user, :bookmarks, :where, :first).and_return(double('bookmark', delete: nil, destroyed?: false))
allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :first).and_return(double('bookmark', delete: nil, destroyed?: false))

xhr :delete, :destroy, :id => 'pleasekillme', :format => :js

Expand Down
96 changes: 48 additions & 48 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def assigns_response
let(:user_query) { 'history' } # query that will get results

it "should have no search history if no search criteria" do
controller.should_receive(:get_search_results)
allow(controller).to receive(:get_search_results)
session[:history] = []
get :index
expect(session[:history]).to be_empty
Expand Down Expand Up @@ -70,7 +70,7 @@ def assigns_response

describe "session" do
before do
controller.stub(:get_search_results)
allow(controller).to receive(:get_search_results)
end
it "should include search hash with key :q" do
get :index, q: user_query
Expand All @@ -95,7 +95,7 @@ def assigns_response
end

it "should render index.html.erb" do
controller.stub(:get_search_results)
allow(controller).to receive(:get_search_results)
get :index
expect(response).to render_template(:index)
end
Expand Down Expand Up @@ -156,8 +156,8 @@ def assigns_response
let(:blacklight_config) { Blacklight::Configuration.new }

before :each do
@controller.stub blacklight_config: blacklight_config
@controller.stub get_search_results: [double, double]
allow(@controller).to receive_messages blacklight_config: blacklight_config
allow(@controller).to receive_messages get_search_results: [double, double]
end

it "should not render when the config is false" do
Expand Down Expand Up @@ -185,7 +185,7 @@ def assigns_response
end

it "with a symbol, it should call a controller method" do
subject.should_receive(:render_some_yaml) do
expect(subject).to receive(:render_some_yaml) do
subject.render nothing: true, layout: false
end

Expand Down Expand Up @@ -256,12 +256,12 @@ def assigns_response
before do
@mock_response = double()
@mock_document = double()
@mock_document.stub(:export_formats => {})
controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
allow(@mock_document).to receive_messages(:export_formats => {})
allow(controller).to receive_messages(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
:get_previous_and_next_documents_for_search => [double(:total => 5), [double("a"), @mock_document, double("b")]])

current_search = Search.create(:query_params => { :q => ""})
controller.stub(:current_search_session => current_search)
allow(controller).to receive_messages(:current_search_session => current_search)

@search_session = { :id => current_search.id }
end
Expand Down Expand Up @@ -296,18 +296,18 @@ def assigns_response
it "should render show.html.erb" do
@mock_response = double()
@mock_document = double()
@mock_document.stub(:export_formats => {})
controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document])
allow(@mock_document).to receive_messages(:export_formats => {})
allow(controller).to receive_messages(:get_solr_response_for_doc_id => [@mock_response, @mock_document])
get :show, :id => doc_id
response.should render_template(:show)
expect(response).to render_template(:show)
end

describe "@document" do
before do
@mock_response = double()
@mock_response.stub(documents: [SolrDocument.new(id: 'my_fake_doc')])
allow(@mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc')])
@mock_document = double()
controller.stub(:find => @mock_response )
allow(controller).to receive_messages(:find => @mock_response )
end
before(:each) do
get :show, :id => doc_id
Expand All @@ -332,9 +332,9 @@ def export_as_mock

before do
@mock_response = double()
@mock_response.stub(:docs => [{ :id => 'my_fake_doc' }])
allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }])
@mock_document = double()
controller.stub(find: @mock_response)
allow(controller).to receive_messages(find: @mock_response)
end

before(:each) do
Expand All @@ -351,12 +351,12 @@ def export_as_mock

before do
@mock_response = double()
@mock_response.stub(:documents => [SolrDocument.new(id: 'my_fake_doc')])
allow(@mock_response).to receive_messages(:documents => [SolrDocument.new(id: 'my_fake_doc')])
@mock_document = double()
controller.stub(:find => @mock_response,
allow(controller).to receive_messages(:find => @mock_response,
:get_single_doc_via_search => @mock_document)

controller.stub(:find => @mock_response,
allow(controller).to receive_messages(:find => @mock_response,
:get_single_doc_via_search => @mock_document)
end

Expand All @@ -379,9 +379,9 @@ def export_as_mock
before do
@mock_response = double()
@mock_document = double()
@mock_response.stub(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')])
allow(@mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')])
@mock_document = double()
controller.stub(find: @mock_response)
allow(controller).to receive_messages(find: @mock_response)

end
it "should return an opensearch description" do
Expand All @@ -398,7 +398,7 @@ def export_as_mock
doc_id = '2007020969'
let(:mock_response) { double(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')]) }
before do
controller.stub(find: mock_response)
allow(controller).to receive_messages(find: mock_response)
request.env["HTTP_REFERER"] = "/catalog/#{doc_id}"
SolrDocument.use_extension( Blacklight::Solr::Document::Email )
SolrDocument.use_extension( Blacklight::Solr::Document::Sms )
Expand All @@ -418,8 +418,8 @@ def export_as_mock
end
it "should redirect back to the record upon success" do
mock_mailer = double
mock_mailer.should_receive(:deliver)
RecordMailer.should_receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer
allow(mock_mailer).to receive(:deliver)
allow(RecordMailer).to receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer

post :email, :id => doc_id, :to => 'test_email@projectblacklight.org', :message => 'xyz'
expect(request.flash[:error]).to be_nil
Expand Down Expand Up @@ -456,8 +456,8 @@ def export_as_mock
end
it "should redirect back to the record upon success" do
post :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
request.flash[:error].should be_nil
request.should redirect_to(catalog_path(doc_id))
expect(request.flash[:error]).to eq nil
expect(request).to redirect_to(catalog_path(doc_id))
end

it "should render sms_sent template for XHR requests" do
Expand All @@ -471,14 +471,14 @@ def export_as_mock
describe "errors" do
it "should return status 404 for a record that doesn't exist" do
@mock_response = double(documents: [])
controller.stub(:find => @mock_response)
allow(controller).to receive_messages(:find => @mock_response)
get :show, :id=>"987654321"
expect(response.status).to eq 404
expect(response.content_type).to eq Mime::HTML
end
it "should return status 404 for a record that doesn't exist even for non-html format" do
@mock_response = double(documents: [])
controller.stub(:find => @mock_response)
allow(controller).to receive_messages(:find => @mock_response)

get :show, :id=>"987654321", :format => "xml"
expect(response.status).to eq 404
Expand All @@ -489,9 +489,9 @@ def export_as_mock
req = {}
res = {}
fake_error = RSolr::Error::Http.new(req, res)
Rails.env.stub(:test? => false)
controller.stub(:get_search_results) { |*args| raise fake_error }
controller.logger.should_receive(:error).with(fake_error)
allow(Rails.env).to receive_messages(:test? => false)
allow(controller).to receive(:get_search_results) { |*args| raise fake_error }
expect(controller.logger).to receive(:error).with(fake_error)
get :index, :q=>"+"

expect(response.redirect_url).to eq root_url
Expand All @@ -504,9 +504,9 @@ def export_as_mock
req = {}
res = {}
fake_error = RSolr::Error::Http.new(req, res)
controller.stub(:get_search_results) { |*args| raise fake_error }
controller.flash.stub(:sweep)
controller.stub(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
allow(controller).to receive(:get_search_results) { |*args| raise fake_error }
allow(controller.flash).to receive(:sweep)
allow(controller).to receive(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
expect {
get :index, :q=>"+"
}.to raise_error
Expand All @@ -518,7 +518,7 @@ def export_as_mock
render_views

before do
controller.stub(:has_user_authentication_provider?) { false }
allow(controller).to receive(:has_user_authentication_provider?) { false }
end

it "should not show user util links" do
Expand Down Expand Up @@ -557,8 +557,8 @@ def export_as_mock
describe 'render_search_results_as_json' do
before do
controller.instance_variable_set :@document_list, [{id: '123', title_t: 'Book1'}, {id: '456', title_t: 'Book2'}]
controller.stub(:pagination_info).and_return({current_page: 1, next_page: 2, prev_page: nil})
controller.stub(:search_facets_as_json).and_return(
allow(controller).to receive(:pagination_info).and_return({current_page: 1, next_page: 2, prev_page: nil})
allow(controller).to receive(:search_facets_as_json).and_return(
[{name: "format", label: "Format", items: [{value: 'Book', hits: 30, label: 'Book'}]}])
end

Expand Down Expand Up @@ -595,7 +595,7 @@ def export_as_mock
end

it "should remove searches from the list when the list gets too big" do
controller.stub(:blacklight_config).and_return(double(:search_history_window => 5))
allow(controller).to receive(:blacklight_config).and_return(double(:search_history_window => 5))
session[:history] = (0..4).to_a.reverse

expect(session[:history]).to have(5).items
Expand All @@ -609,15 +609,15 @@ def export_as_mock

describe "current_search_session" do
it "should create a session if we're on an search action" do
controller.stub(:action_name => "index")
controller.stub(:params => { :q => "x", :page => 5})
allow(controller).to receive_messages(:action_name => "index")
allow(controller).to receive_messages(:params => { :q => "x", :page => 5})
session = controller.send(:current_search_session)
expect(session.query_params).to include(:q => "x")
expect(session.query_params).to_not include(:page => 5)
end

it "should create a session if a search context was provided" do
controller.stub(:params => { :search_context => JSON.dump(:q => "x")})
allow(controller).to receive_messages(:params => { :search_context => JSON.dump(:q => "x")})
session = controller.send(:current_search_session)
expect(session.query_params).to include("q" => "x")
end
Expand All @@ -626,7 +626,7 @@ def export_as_mock
s = Search.create(:query_params => { :q => "x" })
session[:history] ||= []
session[:history] << s.id
controller.stub(:params => { :search_id => s.id})
allow(controller).to receive_messages(:params => { :search_id => s.id})
session = controller.send(:current_search_session)
expect(session.query_params).to include(:q => "x")
expect(session).to eq(s)
Expand All @@ -647,16 +647,16 @@ def export_as_mock
describe "#has_search_parameters?" do
subject { controller.has_search_parameters? }
describe "none" do
before { controller.stub(params: { }) }
it { should be_false }
before { allow(controller).to receive_messages(params: { }) }
it { should be false }
end
describe "with a query" do
before { controller.stub(params: { q: 'hello' }) }
it { should be_true }
before { allow(controller).to receive_messages(params: { q: 'hello' }) }
it { should be true }
end
describe "with a facet" do
before { controller.stub(params: { f: { "field" => ["value"]} }) }
it { should be_true }
before { allow(controller).to receive_messages(params: { f: { "field" => ["value"]} }) }
it { should be true }
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/features/alternate_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "Alternate Controller Behaviors" do
it "should have the correct per-page form" do
visit alternate_index_path
page.should have_selector("form[action='#{alternate_index_url}']")
expect(page).to have_selector("form[action='#{alternate_index_url}']")
fill_in "q", :with=>"history"
click_button 'search'
expect(current_path).to match /#{alternate_index_path}/
Expand All @@ -15,7 +15,7 @@

it "should have the correct search field form" do
visit alternate_index_path
page.should have_selector("form[action='#{alternate_index_url}']")
expect(page).to have_selector("form[action='#{alternate_index_url}']")
fill_in "q", :with=>"history"
click_button 'search'
expect(current_path).to match /#{alternate_index_path}/
Expand All @@ -25,7 +25,7 @@

it "should display document thumbnails" do
visit alternate_index_path
page.should have_selector("form[action='#{alternate_index_url}']")
expect(page).to have_selector("form[action='#{alternate_index_url}']")
fill_in "q", :with=>"history"
click_button 'search'
expect(page).to have_selector ".document-thumbnail"
Expand Down
2 changes: 1 addition & 1 deletion spec/features/record_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end
it "should not display 404" do
visit catalog_path('this_id_does_not_exist')
page.driver.status_code.should == 404
expect(page.driver.status_code).to eq 404
expect(page).to have_content "The page you were looking for doesn't exist."
end
end

0 comments on commit d3c7955

Please sign in to comment.