diff --git a/app/helpers/blacklight/catalog_helper_behavior.rb b/app/helpers/blacklight/catalog_helper_behavior.rb
index 4f976c1a5d..c67d31e43f 100644
--- a/app/helpers/blacklight/catalog_helper_behavior.rb
+++ b/app/helpers/blacklight/catalog_helper_behavior.rb
@@ -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
diff --git a/blacklight.gemspec b/blacklight.gemspec
index 257c0743db..d1ba05b4ec 100644
--- a/blacklight.gemspec
+++ b/blacklight.gemspec
@@ -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"
diff --git a/spec/controllers/bookmarks_controller_spec.rb b/spec/controllers/bookmarks_controller_spec.rb
index f3a7df4454..168c3bb49b 100644
--- a/spec/controllers/bookmarks_controller_spec.rb
+++ b/spec/controllers/bookmarks_controller_spec.rb
@@ -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
@@ -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
diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb
index 01c0de5e72..66f7cba5e2 100644
--- a/spec/controllers/catalog_controller_spec.rb
+++ b/spec/controllers/catalog_controller_spec.rb
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 )
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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
diff --git a/spec/features/alternate_controller_spec.rb b/spec/features/alternate_controller_spec.rb
index 88f0a5247c..28b823fc62 100644
--- a/spec/features/alternate_controller_spec.rb
+++ b/spec/features/alternate_controller_spec.rb
@@ -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}/
@@ -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}/
@@ -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"
diff --git a/spec/features/record_view_spec.rb b/spec/features/record_view_spec.rb
index 94f814f343..5fda62af6d 100644
--- a/spec/features/record_view_spec.rb
+++ b/spec/features/record_view_spec.rb
@@ -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
diff --git a/spec/features/search_filters_spec.rb b/spec/features/search_filters_spec.rb
index 327bec3bac..f8296fc96a 100644
--- a/spec/features/search_filters_spec.rb
+++ b/spec/features/search_filters_spec.rb
@@ -167,14 +167,14 @@
end
end
it "should be collapsed when not selected", :js => true do
- pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
+ skip("Test passes locally but not on Travis.") if ENV['TRAVIS']
visit root_path
within(".blacklight-subject_topic_facet") do
expect(page).not_to have_selector(".panel-collapse", :visible => true)
end
end
it "should expand when the heading is clicked", :js => true do
- pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
+ skip("Test passes locally but not on Travis.") if ENV['TRAVIS']
visit root_path
within(".blacklight-subject_topic_facet") do
expect(page).not_to have_selector(".panel-collapse", :visible => true)
@@ -183,7 +183,7 @@
end
end
it "should expand when the anchor is clicked", :js => true do
- pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
+ skip("Test passes locally but not on Travis.") if ENV['TRAVIS']
visit root_path
within(".blacklight-subject_topic_facet") do
expect(page).not_to have_selector(".panel-collapse", :visible => true)
@@ -192,7 +192,7 @@
end
end
it "should keep selected facets expanded on page load", :js => true do
- pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
+ skip("Test passes locally but not on Travis.") if ENV['TRAVIS']
visit root_path
within(".blacklight-subject_topic_facet") do
click_link "Topic"
diff --git a/spec/features/search_results_spec.rb b/spec/features/search_results_spec.rb
index 7d72bc0f54..351b190919 100644
--- a/spec/features/search_results_spec.rb
+++ b/spec/features/search_results_spec.rb
@@ -5,33 +5,33 @@
describe "Search Results" do
it "should have for an empty query" do
search_for ''
- number_of_results_from_page(page).should == 30
- page.should have_xpath("//a[contains(@href, #{2007020969})]")
+ expect(number_of_results_from_page(page)).to eq 30
+ expect(page).to have_xpath("//a[contains(@href, #{2007020969})]")
search_for 'korea'
- number_of_results_from_page(page).should == 4
+ expect(number_of_results_from_page(page)).to eq 4
end
it "should find same result set with or without diacritcs" do
search_for 'inmul'
- number_of_results_from_page(page).should == 1
- page.should have_xpath("//a[contains(@href, #{77826928})]")
+ expect(number_of_results_from_page(page)).to eq 1
+ expect(page).to have_xpath("//a[contains(@href, #{77826928})]")
search_for 'inmül'
- number_of_results_from_page(page).should == 1
+ expect(number_of_results_from_page(page)).to eq 1
end
it "should find same result set for a case-insensitive query " do
search_for 'inmul'
- number_of_results_from_page(page).should == 1
- page.should have_xpath("//a[contains(@href, #{77826928})]")
+ expect(number_of_results_from_page(page)).to eq 1
+ expect(page).to have_xpath("//a[contains(@href, #{77826928})]")
search_for 'INMUL'
- number_of_results_from_page(page).should == 1
+ expect(number_of_results_from_page(page)).to eq 1
end
it "should order by relevancy" do
search_for "Korea"
- position_in_result_page(page, '77826928').should == 1
- position_in_result_page(page, '94120425').should == 2
+ expect(position_in_result_page(page, '77826928')).to eq 1
+ expect(position_in_result_page(page, '94120425')).to eq 2
end
@@ -39,7 +39,7 @@
visit root_path
tmp_value = Capybara.ignore_hidden_elements
Capybara.ignore_hidden_elements = false
- page.should have_xpath("//link[contains(@rel, 'search')]")
+ expect(page).to have_xpath("//link[contains(@rel, 'search')]")
expect(page.find(:xpath, "//link[contains(@rel, 'search')]")[:href]).to eq "http://www.example.com/catalog/opensearch.xml"
Capybara.ignore_hidden_elements = tmp_value
end
diff --git a/spec/helpers/blacklight_helper_spec.rb b/spec/helpers/blacklight_helper_spec.rb
index f854e0a4d4..c28b130713 100644
--- a/spec/helpers/blacklight_helper_spec.rb
+++ b/spec/helpers/blacklight_helper_spec.rb
@@ -12,7 +12,7 @@ def blacklight_config
end
before(:each) do
- helper.stub(:search_action_path) do |*args|
+ allow(helper).to receive(:search_action_path) do |*args|
catalog_index_url *args
end
end
@@ -23,8 +23,8 @@ def current_search_session
describe "#application_name", :test => true do
it "should use the Rails application config application_name if available" do
- Rails.application.config.stub(:application_name => 'asdf')
- Rails.application.config.should_receive(:respond_to?).with(:application_name).and_return(true)
+ allow(Rails.application.config).to receive(:application_name).and_return('asdf')
+ allow(Rails.application.config).to receive(:respond_to?).with(:application_name).and_return(true)
expect(application_name).to eq 'asdf'
end
it "should default to 'Blacklight'" do
@@ -70,7 +70,7 @@ def mock_document_app_helper_url *args
@doc_id = "MOCK_ID1"
@document = MockDocumentAppHelper.new(:id => @doc_id)
render_params = {:controller => "controller", :action => "action"}
- helper.stub(:params).and_return(render_params)
+ allow(helper).to receive(:params).and_return(render_params)
end
it "generates tags" do
@@ -79,7 +79,7 @@ def mock_document_app_helper_url *args
tmp_value = Capybara.ignore_hidden_elements
Capybara.ignore_hidden_elements = false
@document.export_formats.each_pair do |format, spec|
- response.should have_selector("link[href$='.#{ format }']") do |matches|
+ expect(response).to have_selector("link[href$='.#{ format }']") do |matches|
expect(matches).to have(1).match
tag = matches[0]
expect(tag.attributes["rel"].value).to eq "alternate"
@@ -119,10 +119,10 @@ def mock_document_app_helper_url *args
end
@document = SolrDocument.new('title_display' => "A Fake Document", 'id'=>'8')
- helper.stub(:blacklight_config).and_return(@config)
- helper.stub(:has_user_authentication_provider?).and_return(true)
- helper.stub(:current_or_guest_user).and_return(User.new)
- helper.stub(current_bookmarks: [])
+ allow(helper).to receive(:blacklight_config).and_return(@config)
+ allow(helper).to receive(:has_user_authentication_provider?).and_return(true)
+ allow(helper).to receive(:current_or_guest_user).and_return(User.new)
+ allow(helper).to receive_messages(current_bookmarks: [])
end
describe "render_index_doc_actions" do
it "should render partials" do
@@ -140,43 +140,43 @@ def mock_document_app_helper_url *args
describe "#should_render_index_field?" do
before do
- helper.stub(should_render_field?: true, document_has_value?: true)
+ allow(helper).to receive_messages(should_render_field?: true, document_has_value?: true)
end
it "should be true" do
- expect(helper.should_render_index_field?(double, double)).to be_true
+ expect(helper.should_render_index_field?(double, double)).to be true
end
it "should be false if the document doesn't have a value for the field" do
- helper.stub(document_has_value?: false)
- expect(helper.should_render_index_field?(double, double)).to be_false
+ allow(helper).to receive_messages(document_has_value?: false)
+ expect(helper.should_render_index_field?(double, double)).to be false
end
it "should be false if the configuration has the field disabled" do
- helper.stub(should_render_field?: false)
- expect(helper.should_render_index_field?(double, double)).to be_false
+ allow(helper).to receive_messages(should_render_field?: false)
+ expect(helper.should_render_index_field?(double, double)).to be false
end
end
describe "#should_render_show_field?" do
before do
- helper.stub(should_render_field?: true, document_has_value?: true)
+ allow(helper).to receive_messages(should_render_field?: true, document_has_value?: true)
end
it "should be true" do
- expect(helper.should_render_show_field?(double, double)).to be_true
+ expect(helper.should_render_show_field?(double, double)).to be true
end
it "should be false if the document doesn't have a value for the field" do
- helper.stub(document_has_value?: false)
- expect(helper.should_render_show_field?(double, double)).to be_false
+ allow(helper).to receive_messages(document_has_value?: false)
+ expect(helper.should_render_show_field?(double, double)).to be false
end
it "should be false if the configuration has the field disabled" do
- helper.stub(should_render_field?: false)
- expect(helper.should_render_show_field?(double, double)).to be_false
+ allow(helper).to receive_messages(should_render_field?: false)
+ expect(helper.should_render_show_field?(double, double)).to be false
end
end
@@ -192,65 +192,65 @@ def mock_document_app_helper_url *args
config.add_index_field 'explicit_accessor', :accessor => :solr_doc_accessor
config.add_index_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg
end
- helper.stub(:blacklight_config).and_return(@config)
+ allow(helper).to receive(:blacklight_config).and_return(@config)
end
it "should check for an explicit value" do
doc = double()
- doc.should_not_receive(:get).with('asdf', :sep => nil)
+ expect(doc).to_not receive(:get).with('asdf', :sep => nil)
value = helper.render_index_field_value :value => 'asdf', :document => doc, :field => 'asdf'
expect(value).to eq 'asdf'
end
it "should check for a helper method to call" do
doc = double()
- doc.should_receive(:get).with('asdf', :sep => nil)
- helper.stub(:render_asdf_index_field).and_return('custom asdf value')
+ allow(doc).to receive(:get).with('asdf', :sep => nil)
+ allow(helper).to receive(:render_asdf_index_field).and_return('custom asdf value')
value = helper.render_index_field_value :document => doc, :field => 'asdf'
expect(value).to eq 'custom asdf value'
end
it "should check for a link_to_search" do
doc = double()
- doc.should_receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
+ allow(doc).to receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
value = helper.render_index_field_value :document => doc, :field => 'link_to_search_true'
expect(value).to eq helper.link_to("x", helper.search_action_path(:f => { :link_to_search_true => ['x'] }))
end
it "should check for a link_to_search with a field name" do
doc = double()
- doc.should_receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
+ allow(doc).to receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
value = helper.render_index_field_value :document => doc, :field => 'link_to_search_named'
expect(value).to eq helper.link_to("x", helper.search_action_path(:f => { :some_field => ['x'] }))
end
it "should gracefully handle when no highlight field is available" do
doc = double()
- doc.should_not_receive(:get)
- doc.should_receive(:has_highlight_field?).and_return(false)
+ expect(doc).to_not receive(:get)
+ allow(doc).to receive(:has_highlight_field?).and_return(false)
value = helper.render_index_field_value :document => doc, :field => 'highlight'
expect(value).to be_blank
end
it "should check for a highlighted field" do
doc = double()
- doc.should_not_receive(:get)
- doc.should_receive(:has_highlight_field?).and_return(true)
- doc.should_receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
+ expect(doc).to_not receive(:get)
+ allow(doc).to receive(:has_highlight_field?).and_return(true)
+ allow(doc).to receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
value = helper.render_index_field_value :document => doc, :field => 'highlight'
expect(value).to eq 'highlight'
end
it "should check the document field value" do
doc = double()
- doc.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
+ allow(doc).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
value = helper.render_index_field_value :document => doc, :field => 'qwer'
expect(value).to eq 'document qwer value'
end
it "should work with index fields that aren't explicitly defined" do
doc = double()
- doc.should_receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
+ allow(doc).to receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
value = helper.render_index_field_value :document => doc, :field => 'mnbv'
expect(value).to eq 'document mnbv value'
end
@@ -289,52 +289,52 @@ def mock_document_app_helper_url *args
config.add_show_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg
end
- helper.stub(:blacklight_config).and_return(@config)
+ allow(helper).to receive(:blacklight_config).and_return(@config)
end
it "should check for an explicit value" do
doc = double()
- doc.should_not_receive(:get).with('asdf', :sep => nil)
- helper.should_not_receive(:render_asdf_document_show_field)
+ expect(doc).to_not receive(:get).with('asdf', :sep => nil)
+ expect(helper).to_not receive(:render_asdf_document_show_field)
value = helper.render_document_show_field_value :value => 'asdf', :document => doc, :field => 'asdf'
expect(value).to eq 'asdf'
end
it "should check for a helper method to call" do
doc = double()
- doc.should_receive(:get).with('asdf', :sep => nil)
- helper.stub(:render_asdf_document_show_field).and_return('custom asdf value')
+ allow(doc).to receive(:get).with('asdf', :sep => nil)
+ allow(helper).to receive(:render_asdf_document_show_field).and_return('custom asdf value')
value = helper.render_document_show_field_value :document => doc, :field => 'asdf'
expect(value).to eq 'custom asdf value'
end
it "should check for a link_to_search" do
doc = double()
- doc.should_receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
+ allow(doc).to receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
value = helper.render_document_show_field_value :document => doc, :field => 'link_to_search_true'
expect(value).to eq helper.link_to("x", helper.search_action_path(:f => { :link_to_search_true => ['x'] }))
end
it "should check for a link_to_search with a field name" do
doc = double()
- doc.should_receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
+ allow(doc).to receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
value = helper.render_document_show_field_value :document => doc, :field => 'link_to_search_named'
expect(value).to eq helper.link_to("x", helper.search_action_path(:f => { :some_field => ['x'] }))
end
it "should gracefully handle when no highlight field is available" do
doc = double()
- doc.should_not_receive(:get)
- doc.should_receive(:has_highlight_field?).and_return(false)
+ expect(doc).to_not receive(:get)
+ allow(doc).to receive(:has_highlight_field?).and_return(false)
value = helper.render_document_show_field_value :document => doc, :field => 'highlight'
expect(value).to be_blank
end
it "should check for a highlighted field" do
doc = double()
- doc.should_not_receive(:get)
- doc.should_receive(:has_highlight_field?).and_return(true)
- doc.should_receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
+ expect(doc).to_not receive(:get)
+ allow(doc).to receive(:has_highlight_field?).and_return(true)
+ allow(doc).to receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
value = helper.render_document_show_field_value :document => doc, :field => 'highlight'
expect(value).to eq 'highlight'
end
@@ -342,14 +342,14 @@ def mock_document_app_helper_url *args
it "should check the document field value" do
doc = double()
- doc.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
+ allow(doc).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
value = helper.render_document_show_field_value :document => doc, :field => 'qwer'
expect(value).to eq 'document qwer value'
end
it "should work with show fields that aren't explicitly defined" do
doc = double()
- doc.should_receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
+ allow(doc).to receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
value = helper.render_document_show_field_value :document => doc, :field => 'mnbv'
expect(value).to eq 'document mnbv value'
end
@@ -383,38 +383,38 @@ def mock_document_app_helper_url *args
describe "#document_has_value?" do
it "should if the document has the field value" do
doc = double()
- doc.stub(:has?).with('asdf').and_return(true)
+ allow(doc).to receive(:has?).with('asdf').and_return(true)
field_config = double(:field => 'asdf')
- helper.document_has_value?(doc, field_config).should == true
+ expect(helper.document_has_value?(doc, field_config)).to eq true
end
it "should if the document has a highlight field value" do
doc = double()
- doc.stub(:has?).with('asdf').and_return(false)
- doc.stub(:has_highlight_field?).with('asdf').and_return(true)
+ allow(doc).to receive(:has?).with('asdf').and_return(false)
+ allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(true)
field_config = double(:field => 'asdf', :highlight => true)
- helper.document_has_value?(doc, field_config).should == true
+ expect(helper.document_has_value?(doc, field_config)).to eq true
end
it "should if the field has a model accessor" do
doc = double()
- doc.stub(:has?).with('asdf').and_return(false)
- doc.stub(:has_highlight_field?).with('asdf').and_return(false)
+ allow(doc).to receive(:has?).with('asdf').and_return(false)
+ allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(false)
field_config = double(:field => 'asdf', :highlight => true, :accessor => true)
- helper.document_has_value?(doc, field_config).should == true
+ expect(helper.document_has_value?(doc, field_config)).to eq true
end
end
describe "render_grouped_response?" do
it "should check if the response ivar contains grouped data" do
assign(:response, double("SolrResponse", :grouped? => true))
- expect(helper.render_grouped_response?).to be_true
+ expect(helper.render_grouped_response?).to be true
end
it "should check if the response param contains grouped data" do
response = double("SolrResponse", :grouped? => true)
- expect(helper.render_grouped_response?(response)).to be_true
+ expect(helper.render_grouped_response?(response)).to be true
end
end
@@ -424,14 +424,14 @@ def mock_document_app_helper_url *args
describe "render_field_value" do
before do
- Deprecation.stub(:warn)
+ allow(Deprecation).to receive(:warn)
end
it "should join and html-safe values" do
expect(helper.render_field_value(['a', 'b'])).to eq "a, b"
end
it "should join values using the field_value_separator" do
- helper.stub(:field_value_separator).and_return(" -- ")
+ allow(helper).to receive(:field_value_separator).and_return(" -- ")
expect(helper.render_field_value(['a', 'b'])).to eq "a -- b"
end
@@ -446,40 +446,40 @@ def mock_document_app_helper_url *args
describe "should_show_spellcheck_suggestions?" do
before :each do
- helper.stub spell_check_max: 5
+ allow(helper).to receive_messages spell_check_max: 5
end
it "should not show suggestions if there are enough results" do
response = double(total: 10)
- expect(helper.should_show_spellcheck_suggestions? response).to be_false
+ expect(helper.should_show_spellcheck_suggestions? response).to be false
end
it "should only show suggestions if there are very few results" do
response = double(total: 4, spelling: double(words: [1]))
- expect(helper.should_show_spellcheck_suggestions? response).to be_true
+ expect(helper.should_show_spellcheck_suggestions? response).to be true
end
it "should show suggestions only if there are spelling suggestions available" do
response = double(total: 4, spelling: double(words: []))
- expect(helper.should_show_spellcheck_suggestions? response).to be_false
+ expect(helper.should_show_spellcheck_suggestions? response).to be false
end
end
describe "#render_document_partials" do
let(:doc) { double }
before do
- helper.stub(document_partial_path_templates: [])
+ allow(helper).to receive_messages(document_partial_path_templates: [])
end
it "should get the document format from document_partial_name" do
- helper.should_receive(:document_partial_name).with(doc, :xyz)
+ allow(helper).to receive(:document_partial_name).with(doc, :xyz)
helper.render_document_partial(doc, :xyz)
end
context "with a 1-arg form of document_partial_name" do
it "should only call the 1-arg form of the document_partial_name" do
- helper.should_receive(:method).with(:document_partial_name).and_return(double(arity: 1))
- helper.should_receive(:document_partial_name).with(doc)
- Deprecation.should_receive(:warn)
+ allow(helper).to receive(:method).with(:document_partial_name).and_return(double(arity: 1))
+ allow(helper).to receive(:document_partial_name).with(doc)
+ allow(Deprecation).to receive(:warn)
helper.render_document_partial(doc, nil)
end
end
@@ -489,7 +489,7 @@ def mock_document_app_helper_url *args
let(:blacklight_config) { Blacklight::Configuration.new }
before do
- helper.stub(blacklight_config: blacklight_config)
+ allow(helper).to receive_messages(blacklight_config: blacklight_config)
end
context "with a solr document with empty fields" do
@@ -573,8 +573,8 @@ def mock_document_app_helper_url *args
describe "#render_document_index" do
it "should render the document index with the current view type" do
- helper.stub(document_index_view_type: :current_view)
- helper.should_receive(:render_document_index_with_view).with(:current_view, [], a: 1, b: 2)
+ allow(helper).to receive_messages(document_index_view_type: :current_view)
+ allow(helper).to receive(:render_document_index_with_view).with(:current_view, [], a: 1, b: 2)
helper.render_document_index [], a: 1, b: 2
end
end
diff --git a/spec/helpers/catalog_helper_spec.rb b/spec/helpers/catalog_helper_spec.rb
index 74c7960b0a..c2434db2a5 100644
--- a/spec/helpers/catalog_helper_spec.rb
+++ b/spec/helpers/catalog_helper_spec.rb
@@ -14,7 +14,7 @@ def mock_response args
mock_response = Kaminari.paginate_array(mock_docs).page(current_page).per(per_page)
- mock_response.stub(:docs).and_return(mock_docs.slice(start, per_page))
+ allow(mock_response).to receive(:docs).and_return(mock_docs.slice(start, per_page))
mock_response
end
@@ -62,7 +62,7 @@ def render_grouped_response?
it "should use the model_name from the response" do
response = mock_response :total => 1
- response.stub(:model_name).and_return(double(:human => 'thingy'))
+ allow(response).to receive(:model_name).and_return(double(:human => 'thingy'))
html = page_entries_info(response)
expect(html).to eq "1 thingy found"
@@ -126,82 +126,82 @@ def render_grouped_response?
describe "should_autofocus_on_search_box?" do
it "should be focused if we're on a catalog-like index page without query or facet parameters" do
- helper.stub(controller: CatalogController.new, action_name: "index", has_search_parameters?: false)
- expect(helper.should_autofocus_on_search_box?).to be_true
+ allow(helper).to receive_messages(controller: CatalogController.new, action_name: "index", has_search_parameters?: false)
+ expect(helper.should_autofocus_on_search_box?).to be true
end
it "should not be focused if we're not on a catalog controller" do
- helper.stub(controller: ApplicationController.new)
- expect(helper.should_autofocus_on_search_box?).to be_false
+ allow(helper).to receive_messages(controller: ApplicationController.new)
+ expect(helper.should_autofocus_on_search_box?).to be false
end
it "should not be focused if we're not on a catalog controller index" do
- helper.stub(controller: CatalogController.new, action_name: "show")
- expect(helper.should_autofocus_on_search_box?).to be_false
+ allow(helper).to receive_messages(controller: CatalogController.new, action_name: "show")
+ expect(helper.should_autofocus_on_search_box?).to be false
end
it "should not be focused if a search parameters are provided" do
- helper.stub(controller: CatalogController.new, action_name: "index", has_search_parameters?: true)
- expect(helper.should_autofocus_on_search_box?).to be_false
+ allow(helper).to receive_messages(controller: CatalogController.new, action_name: "index", has_search_parameters?: true)
+ expect(helper.should_autofocus_on_search_box?).to be false
end
end
describe "has_thumbnail?" do
it "should have a thumbnail if a thumbnail_method is configured" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
document = double()
- expect(helper.has_thumbnail? document).to be_true
+ expect(helper.has_thumbnail? document).to be true
end
it "should have a thumbnail if a thumbnail_field is configured and it exists in the document" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
document = double(:has? => true)
- expect(helper.has_thumbnail? document).to be_true
+ expect(helper.has_thumbnail? document).to be true
end
it "should not have a thumbnail if the thumbnail_field is missing from the document" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
document = double(:has? => false)
- expect(helper.has_thumbnail? document).to be_false
+ expect(helper.has_thumbnail? document).to be false
end
it "should not have a thumbnail if none of the fields are configured" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))
- expect(helper.has_thumbnail? double()).to be_false
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))
+ expect(helper.has_thumbnail? double()).to be_falsey
end
end
describe "render_thumbnail_tag" do
let(:document) { double }
it "should call the provided thumbnail method" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
- helper.stub(:xyz => "some-thumbnail")
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
+ allow(helper).to receive_messages(:xyz => "some-thumbnail")
- helper.should_receive(:link_to_document).with(document, :label => "some-thumbnail")
+ allow(helper).to receive(:link_to_document).with(document, :label => "some-thumbnail")
helper.render_thumbnail_tag document
end
it "should create an image tag from the given field" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
- document.stub(:has?).with(:xyz).and_return(true)
- document.stub(:first).with(:xyz).and_return("http://example.com/some.jpg")
+ allow(document).to receive(:has?).with(:xyz).and_return(true)
+ allow(document).to receive(:first).with(:xyz).and_return("http://example.com/some.jpg")
- helper.should_receive(:link_to_document).with(document, :label => image_tag("http://example.com/some.jpg"))
+ allow(helper).to receive(:link_to_document).with(document, :label => image_tag("http://example.com/some.jpg"))
helper.render_thumbnail_tag document
end
it "should not link to the document if the url options are false" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
- helper.stub(:xyz => "some-thumbnail")
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
+ allow(helper).to receive_messages(:xyz => "some-thumbnail")
result = helper.render_thumbnail_tag document, {}, false
expect(result).to eq "some-thumbnail"
end
it "should not link to the document if the url options have :suppress_link" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
- helper.stub(:xyz => "some-thumbnail")
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
+ allow(helper).to receive_messages(:xyz => "some-thumbnail")
result = helper.render_thumbnail_tag document, {}, suppress_link: true
expect(result).to eq "some-thumbnail"
@@ -209,13 +209,13 @@ def render_grouped_response?
it "should return nil if no thumbnail is available" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))
expect(helper.render_thumbnail_tag document).to be_nil
end
it "should return nil if no thumbnail is returned from the thumbnail method" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
- helper.stub(:xyz => nil)
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
+ allow(helper).to receive_messages(:xyz => nil)
expect(helper.render_thumbnail_tag document).to be_nil
end
@@ -223,17 +223,17 @@ def render_grouped_response?
describe "thumbnail_url" do
it "should pull the configured thumbnail field out of the document" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
document = double()
- document.stub(:has?).with(:xyz).and_return(true)
- document.stub(:first).with(:xyz).and_return("asdf")
+ allow(document).to receive(:has?).with(:xyz).and_return(true)
+ allow(document).to receive(:first).with(:xyz).and_return("asdf")
expect(helper.thumbnail_url document).to eq("asdf")
end
it "should return nil if the thumbnail field doesn't exist" do
- helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
+ allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
document = double()
- document.stub(:has?).with(:xyz).and_return(false)
+ allow(document).to receive(:has?).with(:xyz).and_return(false)
expect(helper.thumbnail_url document).to be_nil
end
end
diff --git a/spec/helpers/configuration_helper_spec.rb b/spec/helpers/configuration_helper_spec.rb
index 1126d63271..be37e2f390 100644
--- a/spec/helpers/configuration_helper_spec.rb
+++ b/spec/helpers/configuration_helper_spec.rb
@@ -5,33 +5,33 @@
let(:config_value) { double() }
before :each do
- helper.stub(blacklight_config: blacklight_config)
+ allow(helper).to receive_messages(blacklight_config: blacklight_config)
end
describe "#index_fields" do
it "should pass through the configuration" do
- blacklight_config.stub(index_fields: config_value)
+ allow(blacklight_config).to receive_messages(index_fields: config_value)
expect(helper.index_fields).to eq config_value
end
end
describe "#sort_fields" do
it "should convert the sort fields to select-ready values" do
- blacklight_config.stub(sort_fields: { 'a' => double(key: 'a', label: 'a'), 'b' => double(key: 'b', label: 'b'), c: double(key: 'c', if: false) })
+ allow(blacklight_config).to receive_messages(sort_fields: { 'a' => double(key: 'a', label: 'a'), 'b' => double(key: 'b', label: 'b'), c: double(key: 'c', if: false) })
expect(helper.sort_fields).to eq [['a', 'a'], ['b', 'b']]
end
end
describe "#active_sort_fields" do
it "should restrict the configured sort fields to only those that should be displayed" do
- blacklight_config.stub(sort_fields: { a: double(if: false, unless: false), b: double(if:true, unless: true) })
+ allow(blacklight_config).to receive_messages(sort_fields: { a: double(if: false, unless: false), b: double(if:true, unless: true) })
expect(helper.active_sort_fields).to be_empty
end
end
describe "#document_show_fields" do
it "should pass through the configuration" do
- blacklight_config.stub(show_fields: config_value)
+ allow(blacklight_config).to receive_messages(show_fields: config_value)
expect(helper.document_show_fields).to eq config_value
end
end
@@ -45,7 +45,7 @@
end
it "should default to the first configured index view" do
- blacklight_config.stub(view: { a: true, b: true})
+ allow(blacklight_config).to receive_messages(view: { a: true, b: true})
expect(helper.default_document_index_view_type).to eq :a
end
end
@@ -58,17 +58,17 @@
end
it "should filter views using :if/:unless configuration" do
- helper.document_index_views.should have_key :list
- helper.document_index_views.should_not have_key :abc
- helper.document_index_views.should_not have_key :def
- helper.document_index_views.should_not have_key :xyz
+ expect(helper.document_index_views).to have_key :list
+ expect(helper.document_index_views).to_not have_key :abc
+ expect(helper.document_index_views).to_not have_key :def
+ expect(helper.document_index_views).to_not have_key :xyz
end
end
describe "#has_alternative_views?" do
subject { helper.has_alternative_views?}
describe "with a single view defined" do
- it { should be_false }
+ it { should be false }
end
describe "with multiple views defined" do
@@ -77,13 +77,13 @@
blacklight_config.view.xyz
end
- it { should be_true }
+ it { should be true }
end
end
describe "#spell_check_max" do
it "should pass through the configuration" do
- blacklight_config.stub(spell_max: config_value)
+ allow(blacklight_config).to receive_messages(spell_max: config_value)
expect(helper.spell_check_max).to eq config_value
end
end
@@ -91,8 +91,8 @@
describe "#index_field_label" do
let(:document) { double }
it "should look up the label to display for the given document and field" do
- helper.stub(:index_fields).and_return({ "my_field" => double(label: "some label") })
- helper.should_receive(:solr_field_label).with("some label", :"blacklight.search.fields.index.my_field", :"blacklight.search.fields.my_field")
+ allow(helper).to receive(:index_fields).and_return({ "my_field" => double(label: "some label") })
+ allow(helper).to receive(:solr_field_label).with("some label", :"blacklight.search.fields.index.my_field", :"blacklight.search.fields.my_field")
helper.index_field_label document, "my_field"
end
end
@@ -100,8 +100,8 @@
describe "#document_show_field_label" do
let(:document) { double }
it "should look up the label to display for the given document and field" do
- helper.stub(:document_show_fields).and_return({ "my_field" => double(label: "some label") })
- helper.should_receive(:solr_field_label).with("some label", :"blacklight.search.fields.show.my_field", :"blacklight.search.fields.my_field")
+ allow(helper).to receive(:document_show_fields).and_return({ "my_field" => double(label: "some label") })
+ allow(helper).to receive(:solr_field_label).with("some label", :"blacklight.search.fields.show.my_field", :"blacklight.search.fields.my_field")
helper.document_show_field_label document, "my_field"
end
end
@@ -109,22 +109,22 @@
describe "#facet_field_label" do
let(:document) { double }
it "should look up the label to display for the given document and field" do
- blacklight_config.stub(:facet_fields).and_return({ "my_field" => double(label: "some label") })
- helper.should_receive(:solr_field_label).with("some label", :"blacklight.search.fields.facet.my_field", :"blacklight.search.fields.my_field")
+ allow(blacklight_config).to receive(:facet_fields).and_return({ "my_field" => double(label: "some label") })
+ allow(helper).to receive(:solr_field_label).with("some label", :"blacklight.search.fields.facet.my_field", :"blacklight.search.fields.my_field")
helper.facet_field_label "my_field"
end
end
describe "#solr_field_label" do
it "should look up the label as an i18n string" do
- helper.should_receive(:t).with(:some_key).and_return "my label"
+ allow(helper).to receive(:t).with(:some_key).and_return "my label"
label = helper.solr_field_label :some_key
expect(label).to eq "my label"
end
it "should pass the provided i18n keys to I18n.t" do
- helper.should_receive(:t).with(:key_a, default: [:key_b, "default text"])
+ allow(helper).to receive(:t).with(:key_a, default: [:key_b, "default text"])
label = helper.solr_field_label "default text", :key_a, :key_b
end
@@ -132,31 +132,31 @@
describe "#default_per_page" do
it "should be the configured default per page" do
- helper.stub(blacklight_config: double(default_per_page: 42))
+ allow(helper).to receive_messages(blacklight_config: double(default_per_page: 42))
expect(helper.default_per_page).to eq 42
end
it "should be the first per-page value if a default isn't set" do
- helper.stub(blacklight_config: double(default_per_page: nil, per_page: [11, 22]))
+ allow(helper).to receive_messages(blacklight_config: double(default_per_page: nil, per_page: [11, 22]))
expect(helper.default_per_page).to eq 11
end
end
describe "#default_sort_field" do
it "should be the configured default field" do
- helper.stub(blacklight_config: double(sort_fields: { a: double(default: nil), b: double(key: 'b', default: true) }))
+ allow(helper).to receive_messages(blacklight_config: double(sort_fields: { a: double(default: nil), b: double(key: 'b', default: true) }))
expect(helper.default_sort_field.key).to eq 'b'
end
it "should be the first per-page value if a default isn't set" do
- helper.stub(blacklight_config: double(sort_fields: { a: double(key: 'a', default: nil), b: double(key: 'b', default: nil) }))
+ allow(helper).to receive_messages(blacklight_config: double(sort_fields: { a: double(key: 'a', default: nil), b: double(key: 'b', default: nil) }))
expect(helper.default_sort_field.key).to eq 'a'
end
end
describe "#per_page_options_for_select" do
it "should be the per-page values formatted as options_for_select" do
- helper.stub(blacklight_config: double(per_page: [11, 22, 33]))
+ allow(helper).to receive_messages(blacklight_config: double(per_page: [11, 22, 33]))
expect(helper.per_page_options_for_select).to include ["11 per page", 11]
expect(helper.per_page_options_for_select).to include ["22 per page", 22]
expect(helper.per_page_options_for_select).to include ["33 per page", 33]
@@ -167,21 +167,21 @@
let(:field_config) { double('field config', if: true, unless: false) }
before do
- helper.stub(document_has_value?: true)
+ allow(helper).to receive_messages(document_has_value?: true)
end
it "should be true" do
- expect(helper.should_render_field?(field_config)).to be_true
+ expect(helper.should_render_field?(field_config)).to be true
end
it "should be false if the :if condition is false" do
- field_config.stub(if: false)
- expect(helper.should_render_field?(field_config)).to be_false
+ allow(field_config).to receive_messages(if: false)
+ expect(helper.should_render_field?(field_config)).to be false
end
it "should be false if the :unless condition is true" do
- field_config.stub(unless: true)
- expect(helper.should_render_field?(field_config)).to be_false
+ allow(field_config).to receive_messages(unless: true)
+ expect(helper.should_render_field?(field_config)).to be false
end
end
@@ -192,21 +192,21 @@
end
it "should execute a helper method" do
- helper.stub(:my_helper => true)
- expect(helper.evaluate_configuration_conditional(:my_helper)).to be_true
+ allow(helper).to receive_messages(:my_helper => true)
+ expect(helper.evaluate_configuration_conditional(:my_helper)).to be true
end
it "should call a helper to determine if it should render a field" do
a = double
- helper.should_receive(:my_helper_with_an_arg).with(a).and_return(true)
- expect(helper.evaluate_configuration_conditional(:my_helper_with_an_arg, a)).to be_true
+ allow(helper).to receive(:my_helper_with_an_arg).with(a).and_return(true)
+ expect(helper.evaluate_configuration_conditional(:my_helper_with_an_arg, a)).to be true
end
it "should evaluate a Proc to determine if it should render a field" do
one_arg_lambda = lambda { |context, a| true }
two_arg_lambda = lambda { |context, a, b| true }
- expect(helper.evaluate_configuration_conditional(one_arg_lambda, 1)).to be_true
- expect(helper.evaluate_configuration_conditional(two_arg_lambda, 1, 2)).to be_true
+ expect(helper.evaluate_configuration_conditional(one_arg_lambda, 1)).to be true
+ expect(helper.evaluate_configuration_conditional(two_arg_lambda, 1, 2)).to be true
end
end
@@ -224,7 +224,7 @@
config.add_search_field 'no_display', :qt => 'something', :include_in_simple_select => false
end
- helper.stub(blacklight_config: @config)
+ allow(helper).to receive_messages(blacklight_config: @config)
end
it "should return proper options_for_select arguments" do
diff --git a/spec/helpers/facets_helper_spec.rb b/spec/helpers/facets_helper_spec.rb
index 7c1ebf9f4b..d83da47db0 100644
--- a/spec/helpers/facets_helper_spec.rb
+++ b/spec/helpers/facets_helper_spec.rb
@@ -6,7 +6,7 @@
let(:blacklight_config) { Blacklight::Configuration.new }
before(:each) do
- helper.stub(:blacklight_config).and_return blacklight_config
+ allow(helper).to receive(:blacklight_config).and_return blacklight_config
end
describe "has_facet_values?" do
@@ -40,7 +40,7 @@
config.add_facet_field 'lambda_no_show', :show => lambda { |context, config, field| false }
end
- helper.stub(:blacklight_config => @config)
+ allow(helper).to receive_messages(:blacklight_config => @config)
end
it "should render facets with items" do
@@ -58,14 +58,14 @@
end
it "should call a helper to determine if it should render a field" do
- helper.stub(:my_helper => true)
+ allow(helper).to receive_messages(:my_helper => true)
a = double(:items => [1,2], :name=>'helper_show')
expect(helper.should_render_facet?(a)).to be true
end
it "should call a helper to determine if it should render a field" do
a = double(:items => [1,2], :name=>'helper_with_an_arg_show')
- helper.should_receive(:my_helper_with_an_arg).with(@config.facet_fields['helper_with_an_arg_show'], a).and_return(true)
+ allow(helper).to receive(:my_helper_with_an_arg).with(@config.facet_fields['helper_with_an_arg_show'], a).and_return(true)
expect(helper.should_render_facet?(a)).to be true
end
@@ -86,7 +86,7 @@
config.add_facet_field 'no_collapse', collapse: false
end
- helper.stub(blacklight_config: @config)
+ allow(helper).to receive_messages(blacklight_config: @config)
end
it "should be collapsed by default" do
@@ -109,18 +109,18 @@
it "should retrieve the facet from the response given a string" do
facet_config = double(:query => nil)
facet_field = double()
- helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
+ allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
@response = double()
- @response.should_receive(:facet_by_field_name).with('a').and_return(facet_field)
+ allow(@response).to receive(:facet_by_field_name).with('a').and_return(facet_field)
expect(helper.facet_by_field_name('a')).to eq facet_field
end
it "should also work for facet query fields" do
facet_config = double(:query => {})
- helper.should_receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
- helper.should_receive(:create_rsolr_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
+ allow(helper).to receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
+ allow(helper).to receive(:create_rsolr_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
helper.facet_by_field_name 'a_query_facet_field'
end
@@ -137,7 +137,7 @@
}
before(:each) do
- helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
+ allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
@response = double(:facet_queries => {
'field:search' => 10,
@@ -149,7 +149,7 @@
it"should convert the query facets into a double RSolr FacetField" do
field = helper.facet_by_field_name('my_query_facet_field')
- field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
+ expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
expect(field.name).to eq'my_query_facet_field'
expect(field.items.size).to eq 2
@@ -169,14 +169,14 @@
}
before(:each) do
- helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
+ allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
@response = double(:facet_pivot => { 'field_a,field_b' => [{:field => 'field_a', :value => 'a', :count => 10, :pivot => [{:field => 'field_b', :value => 'b', :count => 2}]}]})
end
it "should convert the pivot facet into a double RSolr FacetField" do
field = helper.facet_by_field_name('my_pivot_facet_field')
- field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
+ expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
expect(field.name).to eq 'my_pivot_facet_field'
@@ -199,9 +199,9 @@
fields = [a,b,empty]
- helper.should_receive(:render_facet_limit).with(a, {})
- helper.should_receive(:render_facet_limit).with(b, {})
- helper.should_receive(:render_facet_limit).with(empty, {})
+ allow(helper).to receive(:render_facet_limit).with(a, {})
+ allow(helper).to receive(:render_facet_limit).with(b, {})
+ allow(helper).to receive(:render_facet_limit).with(empty, {})
helper.render_facet_partials fields
end
@@ -209,10 +209,10 @@
it "should default to the configured facets" do
a = double(:items => [1,2])
b = double(:items => ['b','c'])
- helper.should_receive(:facet_field_names) { [a,b] }
+ allow(helper).to receive(:facet_field_names) { [a,b] }
- helper.should_receive(:render_facet_limit).with(a, {})
- helper.should_receive(:render_facet_limit).with(b, {})
+ allow(helper).to receive(:render_facet_limit).with(a, {})
+ allow(helper).to receive(:render_facet_limit).with(b, {})
helper.render_facet_partials
end
@@ -229,13 +229,13 @@
config.add_facet_field 'my_facet_field_with_custom_partial', :partial => 'custom_facet_partial'
end
- helper.stub(:blacklight_config => @config)
+ allow(helper).to receive_messages(:blacklight_config => @config)
@response = double()
end
it "should set basic local variables" do
@mock_facet = double(:name => 'basic_field', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:partial => 'facet_limit',
+ allow(helper).to receive(:render).with(hash_including(:partial => 'facet_limit',
:locals => {
:solr_field => 'basic_field',
:facet_field => helper.blacklight_config.facet_fields['basic_field'],
@@ -246,37 +246,37 @@
it "should render a facet _not_ declared in the configuration" do
@mock_facet = double(:name => 'asdf', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:partial => 'facet_limit'))
+ allow(helper).to receive(:render).with(hash_including(:partial => 'facet_limit'))
helper.render_facet_limit(@mock_facet)
end
it "should get the partial name from the configuration" do
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
+ allow(helper).to receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
helper.render_facet_limit(@mock_facet)
end
it "should use a partial layout for rendering the facet frame" do
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:layout => 'facet_layout'))
+ allow(helper).to receive(:render).with(hash_including(:layout => 'facet_layout'))
helper.render_facet_limit(@mock_facet)
end
it "should allow the caller to opt-out of facet layouts" do
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:layout => nil))
+ allow(helper).to receive(:render).with(hash_including(:layout => nil))
helper.render_facet_limit(@mock_facet, :layout => nil)
end
it "should render the facet_pivot partial for pivot facets" do
@mock_facet = double(:name => 'pivot_facet_field', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:partial => 'facet_pivot'))
+ allow(helper).to receive(:render).with(hash_including(:partial => 'facet_pivot'))
helper.render_facet_limit(@mock_facet)
end
it "should let you override the rendered partial for pivot facets" do
@mock_facet = double(:name => 'my_pivot_facet_field_with_custom_partial', :items => [1,2,3])
- helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
+ allow(helper).to receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
helper.render_facet_limit(@mock_facet)
end
end
@@ -312,7 +312,7 @@
describe "facet_field_in_params?" do
it "should check if the facet field is selected in the user params" do
- helper.stub(:params => { :f => { "some-field" => ["x"]}})
+ allow(helper).to receive_messages(:params => { :f => { "some-field" => ["x"]}})
expect(helper.facet_field_in_params?("some-field")).to be_truthy
expect(helper.facet_field_in_params?("other-field")).to_not be true
end
@@ -325,9 +325,9 @@
describe "render_facet_value" do
let (:item) { double(:value => 'A', :hits => 10) }
before do
- helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
- helper.should_receive(:facet_display_value).and_return('Z')
- helper.should_receive(:add_facet_params_and_redirect).and_return({controller:'catalog'})
+ allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
+ allow(helper).to receive(:facet_display_value).and_return('Z')
+ allow(helper).to receive(:add_facet_params_and_redirect).and_return({controller:'catalog'})
allow(helper).to receive(:search_action_path) do |*args|
catalog_index_path *args
@@ -352,30 +352,30 @@
describe "#facet_display_value" do
it "should just be the facet value for an ordinary facet" do
- helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil))
+ allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil))
expect(helper.facet_display_value('simple_field', 'asdf')).to eq 'asdf'
end
it "should allow you to pass in a :helper_method argument to the configuration" do
- helper.stub(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
+ allow(helper).to receive(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
- helper.should_receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
+ allow(helper).to receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
expect(helper.facet_display_value('helper_field', 'qwerty')).to eq 'abc'
end
it "should extract the configuration label for a query facet" do
- helper.stub(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil))
+ allow(helper).to receive(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil))
expect(helper.facet_display_value('query_facet', 'query_key')).to eq 'XYZ'
end
it "should localize the label for date-type facets" do
- helper.stub(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil))
+ allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil))
expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq 'Sun, 01 Jan 2012 00:00:00 +0000'
end
it "should localize the label for date-type facets with the supplied localization options" do
- helper.stub(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil))
+ allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil))
expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq '01 Jan 00:00'
end
end
diff --git a/spec/helpers/render_constraints_helper_spec.rb b/spec/helpers/render_constraints_helper_spec.rb
index 9a269532cb..a65d0346e4 100644
--- a/spec/helpers/render_constraints_helper_spec.rb
+++ b/spec/helpers/render_constraints_helper_spec.rb
@@ -11,7 +11,7 @@
before do
# the helper methods below infer paths from the current route
controller.request.path_parameters["controller"] = 'catalog'
- helper.stub(:search_action_path) do |*args|
+ allow(helper).to receive(:search_action_path) do |*args|
catalog_index_path *args
end
end
diff --git a/spec/helpers/search_history_constraints_helper_spec.rb b/spec/helpers/search_history_constraints_helper_spec.rb
index dd0ea2a766..9c811c1213 100644
--- a/spec/helpers/search_history_constraints_helper_spec.rb
+++ b/spec/helpers/search_history_constraints_helper_spec.rb
@@ -12,14 +12,14 @@
end
before(:each) do
- helper.stub(:blacklight_config).and_return(@config)
+ allow(helper).to receive(:blacklight_config).and_return(@config)
end
describe "render_search_to_s_*" do
describe "render_search_to_s_element" do
it "should render basic element" do
response = helper.render_search_to_s_element("key", "value")
- response.should have_selector("span.constraint") do |span|
+ expect(response).to have_selector("span.constraint") do |span|
expect(span).to have_selector("span.filterName", :content => "key:")
expect(span).to have_selector("span.filterValue", :content => "value")
end
@@ -27,14 +27,14 @@
end
it "should escape them that need escaping" do
response = helper.render_search_to_s_element("key>", "value>")
- response.should have_selector("span.constraint") do |span|
- span.should have_selector("span.filterName") do |s2|
+ expect(response).to have_selector("span.constraint") do |span|
+ expect(span).to have_selector("span.filterName") do |s2|
# Note: nokogiri's gettext will unescape the inner html
# which seems to be what rspecs "contains" method calls on
# text nodes - thus the to_s inserted below.
expect(s2).to match(/key>:/)
end
- span.should have_selector("span.filterValue") do |s3|
+ expect(span).to have_selector("span.filterValue") do |s3|
expect(s3).to match(/value>/)
end
end
@@ -42,7 +42,7 @@
end
it "should not escape with options set thus" do
response = helper.render_search_to_s_element("key>", "value>", :escape_key => false, :escape_value => false)
- response.should have_selector("span.constraint") do |span|
+ expect(response).to have_selector("span.constraint") do |span|
expect(span).to have_selector("span.filterName", :content => "key>:")
expect(span).to have_selector("span.filterValue", :content => "value>")
end
@@ -55,9 +55,9 @@
@params = {:q => "history", :f => {"some_facet" => ["value1", "value1"], "other_facet" => ["other1"]}}
end
it "should call lesser methods" do
- helper.stub(:blacklight_config).and_return(@config)
- helper.stub(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(:key => 'default_search_field', :display_label => 'Default'))
- helper.stub(:label_for_search_field).with(nil).and_return('')
+ allow(helper).to receive(:blacklight_config).and_return(@config)
+ allow(helper).to receive(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(:key => 'default_search_field', :display_label => 'Default'))
+ allow(helper).to receive(:label_for_search_field).with(nil).and_return('')
# API hooks expect this to be so
response = helper.render_search_to_s(@params)
diff --git a/spec/helpers/url_helper_spec.rb b/spec/helpers/url_helper_spec.rb
index 9db9730162..530fef3c6d 100644
--- a/spec/helpers/url_helper_spec.rb
+++ b/spec/helpers/url_helper_spec.rb
@@ -10,21 +10,21 @@
end
before(:each) do
- helper.stub(:search_action_path) do |*args|
+ allow(helper).to receive(:search_action_path) do |*args|
catalog_index_url *args
end
- helper.stub(blacklight_config: blacklight_config)
- helper.stub(current_search_session: nil)
- helper.stub(:search_session).and_return({})
+ allow(helper).to receive_messages(blacklight_config: blacklight_config)
+ allow(helper).to receive_messages(current_search_session: nil)
+ allow(helper).to receive(:search_session).and_return({})
end
describe "url_for_document" do
let(:controller_class) { ::CatalogController.new }
before do
- helper.stub(controller: controller_class)
- helper.stub(controller_name: controller_class.controller_name)
+ allow(helper).to receive_messages(controller: controller_class)
+ allow(helper).to receive_messages(controller_name: controller_class.controller_name)
end
it "should be a polymorphic routing-ready object" do
@@ -61,7 +61,7 @@
it "should be a polymorphic route if the solr document responds to #to_model with a non-SolrDocument" do
some_model = double
doc = SolrDocument.new
- doc.stub(to_model: some_model)
+ allow(doc).to receive_messages(to_model: some_model)
expect(helper.url_for_document(doc)).to eq doc
end
end
@@ -71,7 +71,7 @@
let(:bookmarks_query_params) {{ :controller=>'bookmarks'}}
it "should build a link tag to catalog using session[:search] for query params" do
- helper.stub(:current_search_session).and_return double(:query_params => query_params)
+ allow(helper).to receive(:current_search_session).and_return double(:query_params => query_params)
tag = helper.link_back_to_catalog
expect(tag).to match /q=query/
expect(tag).to match /f=facets/
@@ -80,7 +80,7 @@
end
it "should build a link tag to bookmarks using session[:search] for query params" do
- helper.stub(:current_search_session).and_return double(:query_params => bookmarks_query_params)
+ allow(helper).to receive(:current_search_session).and_return double(:query_params => bookmarks_query_params)
tag = helper.link_back_to_catalog
expect(tag).to match /Back to Bookmarks/
expect(tag).to match /\/bookmarks/
@@ -89,16 +89,16 @@
context "with a search context" do
it "should use the current search session counter and per page information to construct the appropriate pagination context" do
- helper.stub(current_search_session: double(query_params: query_params))
- helper.stub(search_session: { 'per_page' => 15, 'counter' => 31 })
+ allow(helper).to receive_messages(current_search_session: double(query_params: query_params))
+ allow(helper).to receive_messages(search_session: { 'per_page' => 15, 'counter' => 31 })
tag = helper.link_back_to_catalog
expect(tag).to match /page=3/
expect(tag).to match /per_page=15/
end
it "should omit per_page if the value is the same as the default" do
- helper.stub(current_search_session: double(query_params: query_params))
- helper.stub(search_session: { 'per_page' => 10, 'counter' => 31 })
+ allow(helper).to receive_messages(current_search_session: double(query_params: query_params))
+ allow(helper).to receive_messages(search_session: { 'per_page' => 10, 'counter' => 31 })
tag = helper.link_back_to_catalog
expect(tag).to match /page=4/
expect(tag).to_not match /per_page=/
@@ -109,7 +109,7 @@
let(:my_engine) { double("Engine") }
it "should call url_for on the engine scope" do
- helper.stub(:current_search_session).and_return double(:query_params => query_params)
+ allow(helper).to receive(:current_search_session).and_return double(:query_params => query_params)
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
tag = helper.link_back_to_catalog(route_set: my_engine)
expect(tag).to match /Back to Search/
@@ -122,28 +122,28 @@
describe "link_to_query" do
it "should build a link tag to catalog using query string (no other params)" do
query = "brilliant"
- helper.stub(params: {})
+ allow(helper).to receive_messages(params: {})
tag = helper.link_to_query(query)
expect(tag).to match /q=#{query}/
expect(tag).to match />#{query}<\/a>/
end
it "should build a link tag to catalog using query string and other existing params" do
query = "wonderful"
- helper.stub(params: {:qt => "title_search", :per_page => "50"})
+ allow(helper).to receive_messages(params: {:qt => "title_search", :per_page => "50"})
tag = helper.link_to_query(query)
expect(tag).to match /qt=title_search/
expect(tag).to match /per_page=50/
end
it "should ignore existing :page param" do
query = "yes"
- helper.stub(params: {:page => "2", :qt => "author_search"})
+ allow(helper).to receive_messages(params: {:page => "2", :qt => "author_search"})
tag = helper.link_to_query(query)
expect(tag).to match /qt=author_search/
expect(tag).to_not match /page/
end
it "should be html_safe" do
query = "brilliant"
- helper.stub(params: {:page => "2", :qt => "author_search"})
+ allow(helper).to receive_messages(params: {:page => "2", :qt => "author_search"})
tag = helper.link_to_query(query)
expect(tag).to be_html_safe
end
@@ -164,7 +164,7 @@
describe "params_for_search" do
before do
- helper.stub(params: { 'default' => 'params'})
+ allow(helper).to receive_messages(params: { 'default' => 'params'})
end
it "should default to using the controller's params" do
@@ -216,7 +216,7 @@
params[:d] = 'd'
end
- result.keys.should_not include(:a, :b)
+ expect(result.keys).to_not include(:a, :b)
expect(result[:c]).to eq 3
expect(result[:d]).to eq 'd'
end
@@ -228,14 +228,14 @@
describe "start_over_path" do
it 'should be the catalog path with the current view type' do
- blacklight_config.stub(:view) { { list: nil, abc: nil} }
- helper.stub(:blacklight_config => blacklight_config)
+ allow(blacklight_config).to receive(:view) { { list: nil, abc: nil} }
+ allow(helper).to receive_messages(:blacklight_config => blacklight_config)
expect(helper.start_over_path(:view => 'abc')).to eq catalog_index_url(:view => 'abc')
end
it 'should not include the current view type if it is the default' do
- blacklight_config.stub(:view) { { list: nil, asdf: nil} }
- helper.stub(:blacklight_config => blacklight_config)
+ allow(blacklight_config).to receive(:view) { { list: nil, asdf: nil} }
+ allow(helper).to receive_messages(:blacklight_config => blacklight_config)
expect(helper.start_over_path(:view => 'list')).to eq catalog_index_url
end
end
@@ -306,7 +306,7 @@
describe "link_to_previous_search" do
it "should link to the given search parameters" do
params = {}
- helper.should_receive(:render_search_to_s).with(params).and_return "link text"
+ allow(helper).to receive(:render_search_to_s).with(params).and_return "link text"
expect(helper.link_to_previous_search({})).to eq helper.link_to("link text", helper.search_action_path)
end
end
@@ -318,7 +318,7 @@
end
it "should add facet value for no pre-existing facets" do
- helper.stub(:params).and_return(@params_no_existing_facet)
+ allow(helper).to receive(:params).and_return(@params_no_existing_facet)
result_params = helper.add_facet_params("facet_field", "facet_value")
expect(result_params[:f]).to be_a_kind_of(Hash)
@@ -327,7 +327,7 @@
end
it "should add a facet param to existing facet constraints" do
- helper.stub(:params).and_return(@params_existing_facets)
+ allow(helper).to receive(:params).and_return(@params_existing_facets)
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
@@ -345,7 +345,7 @@
end
it "should leave non-facet params alone" do
[@params_existing_facets, @params_no_existing_facet].each do |params|
- helper.stub(:params).and_return(params)
+ allow(helper).to receive(:params).and_return(params)
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
@@ -357,9 +357,9 @@
end
it "should replace facets for facets configured as single" do
- helper.should_receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(:single => true))
+ allow(helper).to receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(:single => true))
params = { :f => { 'single_value_facet_field' => 'other_value'}}
- helper.stub(:params).and_return params
+ allow(helper).to receive(:params).and_return params
result_params = helper.add_facet_params('single_value_facet_field', 'my_value')
@@ -403,7 +403,7 @@
Blacklight::Solr::FacetPaginator.request_keys[:sort] => "index",
:id => 'facet_field_name'
}
- helper.stub(:params).and_return(catalog_facet_params)
+ allow(helper).to receive(:params).and_return(catalog_facet_params)
end
it "should not include request parameters used by the facet paginator" do
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
@@ -427,7 +427,7 @@
describe "#bookmarks_export_url" do
it "should be the bookmark url with an encrypted user token" do
- helper.stub(encrypt_user_id: 'xyz', current_or_guest_user: double(id: 123))
+ allow(helper).to receive_messages(encrypt_user_id: 'xyz', current_or_guest_user: double(id: 123))
url = helper.bookmarks_export_url(:html)
expect(url).to eq helper.bookmarks_url(format: :html, encrypted_user_id: 'xyz')
end
diff --git a/spec/lib/blacklight/configurable_spec.rb b/spec/lib/blacklight/configurable_spec.rb
index c49683d98e..f279dfbbf4 100644
--- a/spec/lib/blacklight/configurable_spec.rb
+++ b/spec/lib/blacklight/configurable_spec.rb
@@ -18,17 +18,17 @@ class Child < Parent
end
end
it "should inherit the configuration when subclassed" do
- TestCaseInheritence::Child.blacklight_config.list.should include(1,2,3)
+ expect(TestCaseInheritence::Child.blacklight_config.list).to include(1,2,3)
end
it "inherited version should be a deep copy, not original" do
- TestCaseInheritence::Child.blacklight_config.should_not be(TestCaseInheritence::Parent.blacklight_config)
+ expect(TestCaseInheritence::Child.blacklight_config).to_not be(TestCaseInheritence::Parent.blacklight_config)
TestCaseInheritence::Child.blacklight_config.list << "child_only"
- TestCaseInheritence::Child.blacklight_config.list.should include("child_only")
- TestCaseInheritence::Parent.blacklight_config.list.should_not include("child_only")
+ expect(TestCaseInheritence::Child.blacklight_config.list).to include("child_only")
+ expect(TestCaseInheritence::Parent.blacklight_config.list).to_not include("child_only")
end
end
@@ -45,7 +45,7 @@ class Child < Parent
a = Class.new
a.send(:include, Blacklight::Configurable)
- a.blacklight_config.default_solr_params.should be_empty
+ expect(a.blacklight_config.default_solr_params).to be_empty
end
it "should allow the user to provide a default configuration" do
diff --git a/spec/lib/blacklight/configuration_spec.rb b/spec/lib/blacklight/configuration_spec.rb
index a6925ee9ba..51b948e726 100644
--- a/spec/lib/blacklight/configuration_spec.rb
+++ b/spec/lib/blacklight/configuration_spec.rb
@@ -15,7 +15,7 @@
describe "initialization" do
it "should be an OpenStructWithHashAccess" do
- @config.should be_a_kind_of Blacklight::OpenStructWithHashAccess
+ expect(@config).to be_a_kind_of Blacklight::OpenStructWithHashAccess
end
it "should accept a block for configuration" do
@@ -119,7 +119,7 @@
expect(@config.facet_fields["format"]).to_not be_nil
expect(@config.facet_fields["format"]["label"]).to eq "Format"
- expect(@config.facet_fields["format"]["limit"]).to be_true
+ expect(@config.facet_fields["format"]["limit"]).to be true
end
it "should accept FacetField obj arg" do
@@ -136,7 +136,7 @@
end
expect(@config.facet_fields["format"]).to_not be_nil
- expect(@config.facet_fields["format"].limit).to be_true
+ expect(@config.facet_fields["format"].limit).to be true
end
it "should accept block form" do
@@ -175,7 +175,7 @@
it "should allow you to not show the facet in the facet bar" do
@config.add_facet_field("publication_date", :show=>false)
- expect(@config.facet_fields["publication_date"]['show']).to be_false
+ expect(@config.facet_fields["publication_date"]['show']).to be false
end
it "should raise on nil solr field name" do
@@ -183,7 +183,7 @@
end
it "should take wild-carded field names and dereference them to solr fields" do
- @config.stub(luke_fields: {
+ allow(@config).to receive_messages(luke_fields: {
"some_field_facet" => {},
"another_field_facet" => {},
"a_facet_field" => {},
@@ -227,7 +227,7 @@
end
it "should take wild-carded field names and dereference them to solr fields" do
- @config.stub(luke_fields: {
+ allow(@config).to receive_messages(luke_fields: {
"some_field_display" => {},
"another_field_display" => {},
"a_facet_field" => {},
@@ -272,7 +272,7 @@
end
it "should take wild-carded field names and dereference them to solr fields" do
- @config.stub(luke_fields: {
+ allow(@config).to receive_messages(luke_fields: {
"some_field_display" => {},
"another_field_display" => {},
"a_facet_field" => {},
@@ -289,7 +289,7 @@
it "should accept hash form" do
c = Blacklight::Configuration.new
c.add_search_field(:key => "my_search_key")
- c.search_fields["my_search_key"].should_not be_nil
+ expect(c.search_fields["my_search_key"]).to_not be_nil
end
it "should accept two-arg hash form" do
diff --git a/spec/lib/blacklight/routes_spec.rb b/spec/lib/blacklight/routes_spec.rb
index 9989def7d4..f32a4783df 100644
--- a/spec/lib/blacklight/routes_spec.rb
+++ b/spec/lib/blacklight/routes_spec.rb
@@ -7,8 +7,8 @@
describe "without constraints" do
let(:options) { Hash.new }
it "should define the resources" do
- router.should_receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show]})
- router.should_receive(:resources).with(:records, :only=>[:show])
+ allow(router).to receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show]})
+ allow(router).to receive(:resources).with(:records, :only=>[:show])
subject.solr_document(:records)
end
end
@@ -16,8 +16,8 @@
describe "with constraints" do
let(:options) { { :constraints => {id: /[a-z]+/, format: false } } }
it "should define the resources" do
- router.should_receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show], :constraints=>{:id=>/[a-z]+/, :format=>false} })
- router.should_receive(:resources).with(:records, :only=>[:show], :constraints=>{:id=>/[a-z]+/, :format=>false})
+ allow(router).to receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show], :constraints=>{:id=>/[a-z]+/, :format=>false} })
+ allow(router).to receive(:resources).with(:records, :only=>[:show], :constraints=>{:id=>/[a-z]+/, :format=>false})
subject.solr_document(:records)
end
end
diff --git a/spec/lib/blacklight/search_fields_spec.rb b/spec/lib/blacklight/search_fields_spec.rb
index 9166a5ef18..35f11d72d3 100644
--- a/spec/lib/blacklight/search_fields_spec.rb
+++ b/spec/lib/blacklight/search_fields_spec.rb
@@ -20,7 +20,7 @@ class MockConfig
before(:each) do
@search_field_obj = MockConfig.new
- @search_field_obj.stub(:blacklight_config).and_return(@config)
+ allow(@search_field_obj).to receive(:blacklight_config).and_return(@config)
end
it "should return search field list with calculated :label when needed" do
@@ -50,7 +50,7 @@ class MockConfig
@bad_config = MockConfig.new
end
it "should raise exception on #search_field_list" do
- expect { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
+ expect { allow(@bad_config).to receive(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
config.add_search_field :label => 'All Fields', :qt => 'all_fields'
config.add_search_field 'title', :qt => 'title_search'
}) }.to raise_error
@@ -62,7 +62,7 @@ class MockConfig
@bad_config = MockConfig.new
end
it "should raise on #search_field_list" do
- expect { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
+ expect { allow(@bad_config).to receive(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
config.add_search_field 'my_key', :label => 'All Fields'
config.add_search_field 'my_key', :label => 'title'
diff --git a/spec/lib/blacklight/solr/document_spec.rb b/spec/lib/blacklight/solr/document_spec.rb
index 6fe0a281c5..62f1e77b40 100644
--- a/spec/lib/blacklight/solr/document_spec.rb
+++ b/spec/lib/blacklight/solr/document_spec.rb
@@ -160,7 +160,7 @@ def export_as_marc
# registration in an after, sorry.
end
it "registers format" do
- expect(defined?("Mime::MOCK2")).to be_true
+ expect(defined?("Mime::MOCK2")).to be_truthy
end
it "registers as alias only" do
expect(Mime::Type.lookup("application/mock2")).not_to equal Mime::Type.lookup_by_extension("mock2")
@@ -176,7 +176,7 @@ def export_as_marc
it "should know if a document is exportable" do
doc = MockDocument.new
doc.will_export_as(:marc, "application/marc")
- expect(doc.exports_as?(:marc)).to be_true
+ expect(doc.exports_as?(:marc)).to be true
end
end
diff --git a/spec/lib/blacklight/solr_helper_spec.rb b/spec/lib/blacklight/solr_helper_spec.rb
index 57f7a6068d..27c4444925 100644
--- a/spec/lib/blacklight/solr_helper_spec.rb
+++ b/spec/lib/blacklight/solr_helper_spec.rb
@@ -55,25 +55,25 @@ def logger
describe "#find" do
it "should use the configured solr path" do
blacklight_config.solr_path = 'xyz'
- blacklight_solr.should_receive(:send_and_receive).with('xyz', anything).and_return("{}".to_json)
+ allow(blacklight_solr).to receive(:send_and_receive).with('xyz', anything).and_return("{}".to_json)
expect(subject.find({})).to be_a_kind_of Blacklight::SolrResponse
end
it "should override the configured solr path" do
blacklight_config.solr_path = 'xyz'
- blacklight_solr.should_receive(:send_and_receive).with('abc', anything).and_return("{}".to_json)
+ allow(blacklight_solr).to receive(:send_and_receive).with('abc', anything).and_return("{}".to_json)
expect(subject.find('abc', {})).to be_a_kind_of Blacklight::SolrResponse
end
it "should use a default :qt param" do
blacklight_config.qt = 'xyz'
- blacklight_solr.should_receive(:send_and_receive).with('select', hash_including(params: { qt: 'xyz'})).and_return("{}".to_json)
+ allow(blacklight_solr).to receive(:send_and_receive).with('select', hash_including(params: { qt: 'xyz'})).and_return("{}".to_json)
expect(subject.find({})).to be_a_kind_of Blacklight::SolrResponse
end
it "should use the provided :qt param" do
blacklight_config.qt = 'xyz'
- blacklight_solr.should_receive(:send_and_receive).with('select', hash_including(params: { qt: 'abc'})).and_return("{}".to_json)
+ allow(blacklight_solr).to receive(:send_and_receive).with('select', hash_including(params: { qt: 'abc'})).and_return("{}".to_json)
expect(subject.find({qt: 'abc'})).to be_a_kind_of Blacklight::SolrResponse
end
@@ -82,7 +82,7 @@ def logger
it "defaults to get" do
expect(blacklight_config.http_method).to eq :get
- blacklight_solr.should_receive(:send_and_receive) do |path, params|
+ allow(blacklight_solr).to receive(:send_and_receive) do |path, params|
expect(path).to eq 'select'
expect(params[:method]).to eq :get
expect(params[:params]).to include(:q)
@@ -96,7 +96,7 @@ def logger
it "keep value set to post" do
expect(blacklight_config.http_method).to eq :post
- blacklight_solr.should_receive(:send_and_receive) do |path, params|
+ allow(blacklight_solr).to receive(:send_and_receive) do |path, params|
expect(path).to eq 'select'
expect(params[:method]).to eq :post
expect(params[:data]).to include(:q)
@@ -121,7 +121,7 @@ def logger
it "allows customization of solr_search_params_logic" do
# Normally you'd include a new module into (eg) your CatalogController
# but a sub-class defininig it directly is simpler for test.
- subject.stub(:add_foo_to_solr_params) do |solr_params, user_params|
+ allow(subject).to receive(:add_foo_to_solr_params) do |solr_params, user_params|
solr_params[:wt] = "TESTING"
end
@@ -260,19 +260,19 @@ def logger
end
it "should pass date-type fields through" do
- blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
+ allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
expect(subject.send(:facet_value_to_fq_string, "facet_name", "2012-01-01")).to eq "facet_name:2012\\-01\\-01"
end
it "should escape datetime-type fields" do
- blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
+ allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
expect(subject.send(:facet_value_to_fq_string, "facet_name", "2003-04-09T00:00:00Z")).to eq "facet_name:2003\\-04\\-09T00\\:00\\:00Z"
end
it "should format Date objects correctly" do
- blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:date => nil, :query => nil, :tag => nil))
+ allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(:date => nil, :query => nil, :tag => nil))
d = DateTime.parse("2003-04-09T00:00:00")
expect(subject.send(:facet_value_to_fq_string, "facet_name", d)).to eq "facet_name:2003\\-04\\-09T00\\:00\\:00Z"
end
@@ -282,7 +282,7 @@ def logger
end
it "should add tag local parameters" do
- blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:query => nil, :tag => 'asdf', :date => nil))
+ allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(:query => nil, :tag => 'asdf', :date => nil))
expect(subject.send(:facet_value_to_fq_string, "facet_name", true)).to eq "{!tag=asdf}facet_name:true"
expect(subject.send(:facet_value_to_fq_string, "facet_name", "my value")).to eq "{!raw f=facet_name tag=asdf}my value"
@@ -334,7 +334,7 @@ def logger
describe "overriding of qt parameter" do
it "should return the correct overriden parameter" do
- subject.stub(params: { qt: 'overridden' })
+ allow(subject).to receive_messages(params: { qt: 'overridden' })
expect(subject.solr_search_params[:qt]).to eq "overridden"
end
@@ -397,7 +397,7 @@ def logger
end
it "should add sort parameters" do
- expect(solr_parameters[:facet]).to be_true
+ expect(solr_parameters[:facet]).to be true
expect(solr_parameters[:'facet.field']).to include('test_field')
expect(solr_parameters[:'f.test_field.facet.sort']).to eq 'count'
@@ -494,7 +494,7 @@ def logger
end
before do
- subject.stub params: {:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
+ allow(subject).to receive_messages params: {:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
end
it "should merge parameters from search_field definition" do
@@ -579,7 +579,7 @@ def logger
end
before do
- subject.stub params: {:search_field => "custom_author_key", :q => "query"}
+ allow(subject).to receive_messages params: {:search_field => "custom_author_key", :q => "query"}
end
before do
@@ -666,7 +666,7 @@ def logger
describe 'if facet_list_limit is defined in controller' do
before do
- subject.stub facet_list_limit: 1000
+ allow(subject).to receive_messages facet_list_limit: 1000
end
it 'uses controller method for limit' do
solr_params = subject.solr_facet_params(@facet_field)
@@ -710,7 +710,7 @@ def logger
end
describe "for facet limit parameters config ed" do
before do
- subject.stub params: {:search_field => "test_field", :q => "test query"}
+ allow(subject).to receive_messages params: {:search_field => "test_field", :q => "test query"}
@generated_params = subject.solr_search_params
end
@@ -750,8 +750,8 @@ def logger
end
it "should use the configured request handler " do
- blacklight_config.stub(:default_solr_params).and_return({:qt => 'custom_request_handler'})
- blacklight_solr.should_receive(:send_and_receive) do |path, params|
+ allow(blacklight_config).to receive(:default_solr_params).and_return({:qt => 'custom_request_handler'})
+ allow(blacklight_solr).to receive(:send_and_receive) do |path, params|
expect(path).to eq 'select'
expect(params[:params]['facet.field']).to eq ["format", "{!ex=pub_date_single}pub_date", "subject_topic_facet", "language_facet", "lc_1letter_facet", "subject_geo_facet", "subject_era_facet"]
expect(params[:params]["facet.query"]).to eq ["pub_date:[#{5.years.ago.year} TO *]", "pub_date:[#{10.years.ago.year} TO *]", "pub_date:[#{25.years.ago.year} TO *]"]
@@ -797,7 +797,7 @@ def logger
let(:blacklight_config) { copy_of_catalog_config }
before do
- subject.stub grouped_key_for_results: 'title_sort'
+ allow(subject).to receive_messages grouped_key_for_results: 'title_sort'
(@solr_response, @document_list) = subject.get_search_results({:q => @all_docs_query}, :group => true, :'group.field' => ['pub_date_sort', 'title_sort'])
end
@@ -1048,14 +1048,14 @@ def logger
end
it "should use a provided document request handler " do
- blacklight_config.stub(:document_solr_request_handler => 'document')
- blacklight_solr.should_receive(:send_and_receive).with('select', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
+ allow(blacklight_config).to receive_messages(:document_solr_request_handler => 'document')
+ allow(blacklight_solr).to receive(:send_and_receive).with('select', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
expect { subject.get_solr_response_for_doc_id(@doc_id)}.to raise_error Blacklight::Exceptions::InvalidSolrID
end
it "should use a provided document solr path " do
- blacklight_config.stub(:document_solr_path => 'get')
- blacklight_solr.should_receive(:send_and_receive).with('get', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
+ allow(blacklight_config).to receive_messages(:document_solr_path => 'get')
+ allow(blacklight_solr).to receive(:send_and_receive).with('get', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
expect { subject.get_solr_response_for_doc_id(@doc_id)}.to raise_error Blacklight::Exceptions::InvalidSolrID
end
@@ -1085,7 +1085,7 @@ def logger
end
it "should use the document_unique_id_param configuration" do
- blacklight_config.stub(document_unique_id_param: :ids)
+ allow(blacklight_config).to receive_messages(document_unique_id_param: :ids)
doc_params = subject.solr_doc_params('asdfg')
expect(doc_params[:ids]).to eq 'asdfg'
end
@@ -1105,7 +1105,7 @@ def logger
=begin
# Can't test this properly without updating the "document" request handler in solr
it "should respect the configuration-supplied unique id" do
- SolrDocument.should_receive(:unique_key).and_return("title_display")
+ allow(SolrDocument).to receive(:unique_key).and_return("title_display")
@response, @document = @solr_helper.get_solr_response_for_doc_id('"Strong Medicine speaks"')
@document.id).to eq '"Strong Medicine speaks"'
@document.get(:id)).to eq 2007020969
@@ -1135,7 +1135,7 @@ def logger
doc2 = get_single_doc_via_search(@all_docs_query, nil, @doc_row, @multi_facets)
it "should limit search result by facets when supplied" do
- response2.docs.numFound.should_be < response.docs.numFound
+ response2expect(.docs.numFound).to_be < response.docs.numFound
end
it "should not have facets in the response" do
@@ -1175,7 +1175,7 @@ def logger
expect(solr_response.spelling.words).to include('political') # more freq
=begin
# when we can have multiple suggestions
- solr_response.spelling.words.should_not include('policy') # less freq
+ expect(solr_response.spelling.words).to_not include('policy') # less freq
solr_response.spelling.words).to include('politics') # more freq
solr_response.spelling.words).to include('political') # more freq
=end
@@ -1197,7 +1197,7 @@ def logger
end
it 'search results for multiple terms query with just-poor-enough-terms should have spelling suggestions for each term' do
- pending
+ skip
# get_spelling_suggestion("histo politica").should_not be_nil
end
@@ -1215,7 +1215,7 @@ def logger
it "facet_limit_hash should return hash with key being facet_field and value being configured limit" do
# facet_limit_hash has been removed from solrhelper in refactor. should it go back?
- pending "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
+ skip "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
expect(subject.facet_limit_hash).to eq blacklight_config[:facet][:limits]
end
it "should handle no facet_limits in config" do
@@ -1238,14 +1238,14 @@ def logger
end
it "should get from @response facet.limit if available" do
@response = double()
- @response.stub(:facet_by_field_name).with("language_facet").and_return(double(limit: nil))
+ allow(@response).to receive(:facet_by_field_name).with("language_facet").and_return(double(limit: nil))
subject.instance_variable_set(:@response, @response)
blacklight_config.facet_fields['language_facet'].limit = 10
expect(subject.facet_limit_for("language_facet")).to eq 10
end
it "should get the limit from the facet field in @response" do
@response = double()
- @response.stub(:facet_by_field_name).with("language_facet").and_return(double(limit: 16))
+ allow(@response).to receive(:facet_by_field_name).with("language_facet").and_return(double(limit: 16))
subject.instance_variable_set(:@response, @response)
expect(subject.facet_limit_for("language_facet")).to eq 15
end
@@ -1268,20 +1268,20 @@ def logger
describe "#get_solr_response_for_field_values" do
before do
@mock_response = double()
- @mock_response.stub(documents: [])
+ allow(@mock_response).to receive_messages(documents: [])
end
it "should contruct a solr query based on the field and value pair" do
- subject.should_receive(:find).with(hash_including(:q => "field_name:(value)")).and_return(@mock_response)
+ allow(subject).to receive(:find).with(hash_including(:q => "field_name:(value)")).and_return(@mock_response)
subject.get_solr_response_for_field_values('field_name', 'value')
end
it "should OR multiple values together" do
- subject.should_receive(:find).with(hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
+ allow(subject).to receive(:find).with(hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
subject.get_solr_response_for_field_values('field_name', ['a', 'b'])
end
it "should escape crazy identifiers" do
- subject.should_receive(:find).with(hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
+ allow(subject).to receive(:find).with(hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
subject.get_solr_response_for_field_values('field_name', 'h://"\'')
end
end
@@ -1294,7 +1294,7 @@ def logger
# more like this
# nearby on shelf
it "should raise a Blacklight exception if RSolr can't connect to the Solr instance" do
- blacklight_solr.stub(:send_and_receive).and_raise(Errno::ECONNREFUSED)
+ allow(blacklight_solr).to receive(:send_and_receive).and_raise(Errno::ECONNREFUSED)
expect { subject.find(:a => 123) }.to raise_exception(/Unable to connect to Solr instance/)
end
diff --git a/spec/lib/blacklight/solr_response/group_response_spec.rb b/spec/lib/blacklight/solr_response/group_response_spec.rb
index 16953fab2f..5cf55e6e83 100644
--- a/spec/lib/blacklight/solr_response/group_response_spec.rb
+++ b/spec/lib/blacklight/solr_response/group_response_spec.rb
@@ -12,7 +12,7 @@
describe "groups" do
it "should return an array of Groups" do
- response.grouped.should be_a Array
+ expect(response.grouped).to be_a Array
expect(group.groups).to have(2).items
group.groups.each do |group|
diff --git a/spec/lib/blacklight/solr_response_spec.rb b/spec/lib/blacklight/solr_response_spec.rb
index 267311b3c7..3a87f24446 100644
--- a/spec/lib/blacklight/solr_response_spec.rb
+++ b/spec/lib/blacklight/solr_response_spec.rb
@@ -28,16 +28,16 @@ def create_response
end
it 'should provide facet helpers' do
- r.facets.size.should == 2
+ expect(r.facets.size).to eq 2
field_names = r.facets.collect{|facet|facet.name}
- field_names.include?('cat').should == true
- field_names.include?('manu').should == true
+ expect(field_names.include?('cat')).to be true
+ expect(field_names.include?('manu')).to be true
first_facet = r.facets.select { |x| x.name == 'cat'}.first
- first_facet.name.should == 'cat'
+ expect(first_facet.name).to eq 'cat'
- first_facet.items.size.should == 10
+ expect(first_facet.items.size).to eq 10
expected = "electronics - 14, memory - 3, card - 2, connector - 2, drive - 2, graphics - 2, hard - 2, monitor - 2, search - 2, software - 2"
received = first_facet.items.collect do |item|
@@ -73,7 +73,7 @@ def create_response
it "should provide a model name helper" do
first_doc_model_name = double(:human => 'xyz')
- r.docs.first.stub(:model_name).and_return first_doc_model_name
+ allow(r.docs.first).to receive(:model_name).and_return first_doc_model_name
expect(r.model_name).to eq first_doc_model_name
end
@@ -81,33 +81,33 @@ def create_response
describe "FacetItem" do
it "should work with a field,value tuple" do
item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15)
- item.value.should == 'value'
- item.hits.should == 15
+ expect(item.value).to eq 'value'
+ expect(item.hits).to eq 15
end
it "should work with a field,value + hash triple" do
item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15, :a => 1, :value => 'ignored')
- item.value.should == 'value'
- item.hits.should == 15
- item.a.should == 1
+ expect(item.value).to eq 'value'
+ expect(item.hits).to eq 15
+ expect(item.a).to eq 1
end
it "should work like an openstruct" do
item = Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'value', :hits => 15)
- item.hits.should == 15
- item.value.should == 'value'
- item.should be_a_kind_of(OpenStruct)
+ expect(item.hits).to eq 15
+ expect(item.value).to eq 'value'
+ expect(item).to be_a_kind_of(OpenStruct)
end
it "should provide a label accessor" do
item = Blacklight::SolrResponse::Facets::FacetItem.new('value', :hits => 15)
- item.label.should == 'value'
+ expect(item.label).to eq 'value'
end
it "should use a provided label" do
item = Blacklight::SolrResponse::Facets::FacetItem.new('value', 15, :label => 'custom label')
- item.label.should == 'custom label'
+ expect(item.label).to eq 'custom label'
end
@@ -116,78 +116,78 @@ def create_response
it 'should return the correct value when calling facet_by_field_name' do
r = create_response
facet = r.facet_by_field_name('cat')
- facet.name.should == 'cat'
+ expect(facet.name).to eq 'cat'
end
it 'should provide the responseHeader params' do
raw_response = eval(mock_query_response)
raw_response['responseHeader']['params']['test'] = :test
r = Blacklight::SolrResponse.new(raw_response, raw_response['params'])
- r.params['test'].should == :test
+ expect(r.params['test']).to eq :test
end
it 'should provide the solr-returned params and "rows" should be 11' do
raw_response = eval(mock_query_response)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.params[:rows].to_s.should == '11'
+ expect(r.params[:rows].to_s).to eq '11'
end
it 'should provide the ruby request params if responseHeader["params"] does not exist' do
raw_response = eval(mock_query_response)
raw_response.delete 'responseHeader'
r = Blacklight::SolrResponse.new(raw_response, :rows => 999)
- r.params[:rows].to_s.should == '999'
+ expect(r.params[:rows].to_s).to eq '999'
end
it 'should provide spelling suggestions for regular spellcheck results' do
raw_response = eval(mock_response_with_spellcheck)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.spelling.words.should include("dell")
- r.spelling.words.should include("ultrasharp")
+ expect(r.spelling.words).to include("dell")
+ expect(r.spelling.words).to include("ultrasharp")
end
it 'should provide spelling suggestions for extended spellcheck results' do
raw_response = eval(mock_response_with_spellcheck_extended)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.spelling.words.should include("dell")
- r.spelling.words.should include("ultrasharp")
+ expect(r.spelling.words).to include("dell")
+ expect(r.spelling.words).to include("ultrasharp")
end
it 'should provide no spelling suggestions when extended results and suggestion frequency is the same as original query frequency' do
raw_response = eval(mock_response_with_spellcheck_same_frequency)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.spelling.words.should == []
+ expect(r.spelling.words).to eq []
end
it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.spelling.words.should include("dell")
- r.spelling.words.should include("ultrasharp")
+ expect(r.spelling.words).to include("dell")
+ expect(r.spelling.words).to include("ultrasharp")
end
it 'should provide spelling suggestion collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.spelling.collation.should == 'dell ultrasharp'
+ expect(r.spelling.collation).to eq 'dell ultrasharp'
end
it "should provide MoreLikeThis suggestions" do
raw_response = eval(mock_response_with_more_like_this)
r = Blacklight::SolrResponse.new(raw_response, {})
- r.more_like(double(:id => '79930185')).should have(2).items
+ expect(r.more_like(double(:id => '79930185'))).to have(2).items
end
it "should be empty when the response has no results" do
r = Blacklight::SolrResponse.new({}, {})
- r.stub(:total => 0)
+ allow(r).to receive_messages(:total => 0)
expect(r).to be_empty
end
describe "#export_formats" do
it "should collect the unique export formats for the current response" do
r = Blacklight::SolrResponse.new({}, {})
- r.stub(documents: [double(:export_formats => { a: 1, b: 2}), double(:export_formats => { b: 1, c: 2})])
+ allow(r).to receive_messages(documents: [double(:export_formats => { a: 1, b: 2}), double(:export_formats => { b: 1, c: 2})])
expect(r.export_formats).to include :a, :b
end
end
diff --git a/spec/lib/document_presenter_spec.rb b/spec/lib/document_presenter_spec.rb
index b9bbc7d4c1..434fe78bf7 100644
--- a/spec/lib/document_presenter_spec.rb
+++ b/spec/lib/document_presenter_spec.rb
@@ -22,71 +22,71 @@
end
end
it "should check for an explicit value" do
- document.should_not_receive(:get).with('asdf', :sep => nil)
+ expect(document).to_not receive(:get).with('asdf', :sep => nil)
value = subject.render_index_field_value 'asdf', :value => 'asdf'
expect(value).to eq 'asdf'
end
it "should check for a helper method to call" do
- document.should_receive(:get).with('asdf', :sep => nil)
- request_context.stub(:render_asdf_index_field).and_return('custom asdf value')
+ allow(document).to receive(:get).with('asdf', :sep => nil)
+ allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
value = subject.render_index_field_value 'asdf'
expect(value).to eq 'custom asdf value'
end
it "should check for a link_to_search" do
- document.should_receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
- request_context.should_receive(:add_facet_params).and_return(:f => { :link_to_search_true => ['x'] })
- request_context.should_receive(:search_action_path).with(:f => { :link_to_search_true => ['x'] }).and_return('/foo')
- request_context.should_receive(:link_to).with("x", '/foo').and_return('bar')
+ allow(document).to receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
+ allow(request_context).to receive(:add_facet_params).and_return(:f => { :link_to_search_true => ['x'] })
+ allow(request_context).to receive(:search_action_path).with(:f => { :link_to_search_true => ['x'] }).and_return('/foo')
+ allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
value = subject.render_index_field_value 'link_to_search_true'
expect(value).to eq 'bar'
end
it "should check for a link_to_search with a field name" do
- document.should_receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
- request_context.should_receive(:add_facet_params).and_return(:f => { :some_field => ['x'] })
- request_context.should_receive(:search_action_path).with(:f => { :some_field => ['x'] }).and_return('/foo')
- request_context.should_receive(:link_to).with("x", '/foo').and_return('bar')
+ allow(document).to receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
+ allow(request_context).to receive(:add_facet_params).and_return(:f => { :some_field => ['x'] })
+ allow(request_context).to receive(:search_action_path).with(:f => { :some_field => ['x'] }).and_return('/foo')
+ allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
value = subject.render_index_field_value 'link_to_search_named'
expect(value).to eq 'bar'
end
it "should gracefully handle when no highlight field is available" do
- document.should_not_receive(:get)
- document.should_receive(:has_highlight_field?).and_return(false)
+ expect(document).to_not receive(:get)
+ allow(document).to receive(:has_highlight_field?).and_return(false)
value = subject.render_index_field_value 'highlight'
expect(value).to be_blank
end
it "should check for a highlighted field" do
- document.should_not_receive(:get)
- document.should_receive(:has_highlight_field?).and_return(true)
- document.should_receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
+ expect(document).to_not receive(:get)
+ allow(document).to receive(:has_highlight_field?).and_return(true)
+ allow(document).to receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
value = subject.render_index_field_value 'highlight'
expect(value).to eq 'highlight'
end
it "should check the document field value" do
- document.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
+ allow(document).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
value = subject.render_index_field_value 'qwer'
expect(value).to eq 'document qwer value'
end
it "should work with index fields that aren't explicitly defined" do
- document.should_receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
+ allow(document).to receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
value = subject.render_index_field_value 'mnbv'
expect(value).to eq 'document mnbv value'
end
it "should call an accessor on the solr document" do
- document.stub(:solr_doc_accessor => "123")
+ allow(document).to receive_messages(:solr_doc_accessor => "123")
value = subject.render_index_field_value 'solr_doc_accessor'
expect(value).to eq "123"
end
it "should call an explicit accessor on the solr document" do
- document.stub(:solr_doc_accessor => "123")
+ allow(document).to receive_messages(:solr_doc_accessor => "123")
value = subject.render_index_field_value 'explicit_accessor'
expect(value).to eq "123"
end
@@ -114,77 +114,77 @@
end
it "should check for an explicit value" do
- document.should_not_receive(:get).with('asdf', :sep => nil)
- request_context.should_not_receive(:render_asdf_document_show_field)
+ expect(document).to_not receive(:get).with('asdf', :sep => nil)
+ expect(request_context).to_not receive(:render_asdf_document_show_field)
value = subject.render_document_show_field_value 'asdf', :value => 'val1'
expect(value).to eq 'val1'
end
it "should check for a helper method to call" do
- document.should_receive(:get).with('asdf', :sep => nil)
- request_context.stub(:render_asdf_document_show_field).and_return('custom asdf value')
+ allow(document).to receive(:get).with('asdf', :sep => nil)
+ allow(request_context).to receive(:render_asdf_document_show_field).and_return('custom asdf value')
value = subject.render_document_show_field_value 'asdf'
expect(value).to eq 'custom asdf value'
end
it "should check for a link_to_search" do
- document.should_receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
- request_context.should_receive(:search_action_path).with('').and_return('/foo')
- request_context.should_receive(:link_to).with("x", '/foo').and_return('bar')
+ allow(document).to receive(:get).with('link_to_search_true', :sep => nil).and_return('x')
+ allow(request_context).to receive(:search_action_path).with('').and_return('/foo')
+ allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
value = subject.render_document_show_field_value 'link_to_search_true'
expect(value).to eq 'bar'
end
it "should check for a link_to_search with a field name" do
- document.should_receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
- request_context.should_receive(:search_action_path).with('').and_return('/foo')
- request_context.should_receive(:link_to).with("x", '/foo').and_return('bar')
+ allow(document).to receive(:get).with('link_to_search_named', :sep => nil).and_return('x')
+ allow(request_context).to receive(:search_action_path).with('').and_return('/foo')
+ allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
value = subject.render_document_show_field_value 'link_to_search_named'
expect(value).to eq 'bar'
end
it "should gracefully handle when no highlight field is available" do
- document.should_not_receive(:get)
- document.should_receive(:has_highlight_field?).and_return(false)
+ expect(document).to_not receive(:get)
+ allow(document).to receive(:has_highlight_field?).and_return(false)
value = subject.render_document_show_field_value 'highlight'
expect(value).to be_blank
end
it "should check for a highlighted field" do
- document.should_not_receive(:get)
- document.should_receive(:has_highlight_field?).and_return(true)
- document.should_receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
+ expect(document).to_not receive(:get)
+ allow(document).to receive(:has_highlight_field?).and_return(true)
+ allow(document).to receive(:highlight_field).with('highlight').and_return(['highlight'.html_safe])
value = subject.render_document_show_field_value 'highlight'
expect(value).to eq 'highlight'
end
it "should check the document field value" do
- document.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
+ allow(document).to receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
value = subject.render_document_show_field_value 'qwer'
expect(value).to eq 'document qwer value'
end
it "should work with show fields that aren't explicitly defined" do
- document.should_receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
+ allow(document).to receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
value = subject.render_document_show_field_value 'mnbv'
expect(value).to eq 'document mnbv value'
end
it "should call an accessor on the solr document" do
- document.stub(:solr_doc_accessor => "123")
+ allow(document).to receive_messages(:solr_doc_accessor => "123")
value = subject.render_document_show_field_value 'solr_doc_accessor'
expect(value).to eq "123"
end
it "should call an explicit accessor on the solr document" do
- document.stub(:solr_doc_accessor => "123")
+ allow(document).to receive_messages(:solr_doc_accessor => "123")
value = subject.render_document_show_field_value 'explicit_accessor'
expect(value).to eq "123"
end
it "should call an explicit array-style accessor on the solr document" do
- document.stub(:solr_doc_accessor => double(:some_method => "123"))
+ allow(document).to receive_messages(:solr_doc_accessor => double(:some_method => "123"))
value = subject.render_document_show_field_value 'explicit_array_accessor'
expect(value).to eq "123"
end
@@ -201,7 +201,7 @@
end
it "should join values using the field_value_separator" do
- subject.stub(:field_value_separator).and_return(" -- ")
+ allow(subject).to receive(:field_value_separator).and_return(" -- ")
expect(subject.render_field_value(['a', 'b'])).to eq "a -- b"
end
diff --git a/spec/lib/tasks/blacklight_task_spec.rb b/spec/lib/tasks/blacklight_task_spec.rb
index f1dad867d6..0ea3487d31 100644
--- a/spec/lib/tasks/blacklight_task_spec.rb
+++ b/spec/lib/tasks/blacklight_task_spec.rb
@@ -14,7 +14,7 @@
it "should call Search.delete_old_searches" do
days_old = 7
- Search.should_receive(:delete_old_searches).with(days_old)
+ allow(Search).to receive(:delete_old_searches).with(days_old)
@rake[@task_name].invoke(days_old)
end
diff --git a/spec/models/record_mailer_spec.rb b/spec/models/record_mailer_spec.rb
index c62e5779c3..7099ecc54a 100644
--- a/spec/models/record_mailer_spec.rb
+++ b/spec/models/record_mailer_spec.rb
@@ -4,7 +4,7 @@
describe RecordMailer do
before(:each) do
- RecordMailer.stub(:default) { { :from => 'no-reply@projectblacklight.org' } }
+ allow(RecordMailer).to receive(:default) { { :from => 'no-reply@projectblacklight.org' } }
SolrDocument.use_extension( Blacklight::Solr::Document::Email )
SolrDocument.use_extension( Blacklight::Solr::Document::Sms )
document = SolrDocument.new({:id=>"123456", :format=>["book"], :title_display => "The horn", :language_facet => "English", :author_display => "Janetzky, Kurt"})
diff --git a/spec/models/search_spec.rb b/spec/models/search_spec.rb
index 83eb9f3fbb..5a0f9b0921 100644
--- a/spec/models/search_spec.rb
+++ b/spec/models/search_spec.rb
@@ -14,7 +14,7 @@
it "should return a Hash as the value" do
@search.query_params = @query_params
assert @search.save
- Search.find(@search.id).query_params.should == @query_params
+ expect(Search.find(@search.id).query_params).to eq @query_params
end
end
diff --git a/spec/routing/catalog_routing_spec.rb b/spec/routing/catalog_routing_spec.rb
index 2d53cb8c2b..ed7c02f83f 100644
--- a/spec/routing/catalog_routing_spec.rb
+++ b/spec/routing/catalog_routing_spec.rb
@@ -34,7 +34,7 @@
end
it "should route url-like ids" do
- pending "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
+ skip "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
expect(:get => catalog_path(SolrDocument.new(:id => 'http://example.com'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'http://example.com')
end
@@ -47,7 +47,7 @@
end
it "should route ids with a literal '/" do
- pending "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
+ skip "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
expect(:get => catalog_path(SolrDocument.new(:id => 'and/or'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'and/or')
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 48889b2a57..e113601067 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -23,6 +23,7 @@
require 'rspec/rails'
require 'rspec/its'
+require 'rspec/collection_matchers'
require 'capybara/rspec'
require 'capybara/poltergeist'
diff --git a/spec/support/include_text.rb b/spec/support/include_text.rb
index 22bfe3b32e..f183efe866 100644
--- a/spec/support/include_text.rb
+++ b/spec/support/include_text.rb
@@ -8,14 +8,13 @@ module Matchers
@content.include?(text)
end
- failure_message_for_should do |text|
+ failure_message do |text|
"expected '#{@content}' to contain '#{text}'"
end
- failure_message_for_should_not do |text|
+ failure_message_when_negated do |text|
"expected #{@content} to not contain '#{text}'"
end
end
end
end
-
diff --git a/spec/views/catalog/_constraints.html.erb_spec.rb b/spec/views/catalog/_constraints.html.erb_spec.rb
index 5587ec5025..2902516083 100644
--- a/spec/views/catalog/_constraints.html.erb_spec.rb
+++ b/spec/views/catalog/_constraints.html.erb_spec.rb
@@ -8,25 +8,25 @@
end
it "should render nothing if no constraints are set" do
- view.stub(query_has_constraints?: false)
+ allow(view).to receive_messages(query_has_constraints?: false)
render partial: "catalog/constraints"
expect(rendered).to be_empty
end
it "should render a start over link" do
- view.should_receive(:search_action_path).with({}).and_return('http://xyz')
- view.stub(query_has_constraints?: true)
- view.stub(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:search_action_path).with({}).and_return('http://xyz')
+ allow(view).to receive_messages(query_has_constraints?: true)
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
render partial: "catalog/constraints"
expect(rendered).to have_selector("#startOverLink")
expect(rendered).to have_link("Start Over", :href => 'http://xyz')
end
it "should render a start over link with the current view type" do
- view.should_receive(:search_action_path).with(view: :xyz).and_return('http://xyz?view=xyz')
- view.stub(query_has_constraints?: true)
+ allow(view).to receive(:search_action_path).with(view: :xyz).and_return('http://xyz?view=xyz')
+ allow(view).to receive_messages(query_has_constraints?: true)
params[:view] = 'xyz'
- view.stub(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
render partial: "catalog/constraints"
expect(rendered).to have_selector("#startOverLink")
expect(rendered).to have_link("Start Over", :href => 'http://xyz?view=xyz')
diff --git a/spec/views/catalog/_document.html.erb_spec.rb b/spec/views/catalog/_document.html.erb_spec.rb
index 0c99de98c2..421547d44c 100644
--- a/spec/views/catalog/_document.html.erb_spec.rb
+++ b/spec/views/catalog/_document.html.erb_spec.rb
@@ -10,8 +10,8 @@
end
it "should render the header, thumbnail and index by default" do
- view.stub(:render_grouped_response?).and_return(false)
- view.stub(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:render_grouped_response?).and_return(false)
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
stub_template "catalog/_index_header_default.html.erb" => "document_header"
stub_template "catalog/_thumbnail_default.html.erb" => "thumbnail_default"
stub_template "catalog/_index_default.html.erb" => "index_default"
@@ -25,8 +25,8 @@
it "should use the index.partials parameter to determine the partials to render" do
- view.stub(:render_grouped_response?).and_return(false)
- view.stub(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:render_grouped_response?).and_return(false)
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
blacklight_config.index.partials = ['a', 'b', 'c']
stub_template "catalog/_a_default.html.erb" => "a_partial"
stub_template "catalog/_b_default.html.erb" => "b_partial"
diff --git a/spec/views/catalog/_facet_layout.html.erb_spec.rb b/spec/views/catalog/_facet_layout.html.erb_spec.rb
index e0f2d00b67..394175d36b 100644
--- a/spec/views/catalog/_facet_layout.html.erb_spec.rb
+++ b/spec/views/catalog/_facet_layout.html.erb_spec.rb
@@ -13,7 +13,7 @@
end
before do
- view.stub(blacklight_config: blacklight_config)
+ allow(view).to receive_messages(blacklight_config: blacklight_config)
end
it "should have a facet-specific class" do
@@ -33,7 +33,7 @@
end
it "should be configured to be open by default" do
- facet_field.stub(collapse: false)
+ allow(facet_field).to receive_messages(collapse: false)
render partial: 'catalog/facet_layout', locals: { facet_field: facet_field }
expect(rendered).to_not have_selector '.panel-heading.collapsed'
expect(rendered).to have_selector '.in .panel-body'
diff --git a/spec/views/catalog/_facets.html.erb_spec.rb b/spec/views/catalog/_facets.html.erb_spec.rb
index a3b2023528..5b2058802c 100644
--- a/spec/views/catalog/_facets.html.erb_spec.rb
+++ b/spec/views/catalog/_facets.html.erb_spec.rb
@@ -4,15 +4,15 @@
let(:blacklight_config) { Blacklight::Configuration.new }
before do
- view.stub(blacklight_config: blacklight_config)
- view.stub(:search_action_path) do |*args|
+ allow(view).to receive_messages(blacklight_config: blacklight_config)
+ allow(view).to receive(:search_action_path) do |*args|
catalog_index_url *args
end
end
context "without any facet fields" do
it "should not have a header if no facets are displayed" do
- view.stub(:render_facet_partials => '')
+ allow(view).to receive_messages(:render_facet_partials => '')
render
expect(rendered).to_not have_selector('h4')
end
@@ -27,15 +27,15 @@
blacklight_config.facet_fields['facet_field_1'] = facet_field
@mock_display_facet_1 = double(:name => 'facet_field_1', sort: nil, offset: nil, :items => [Blacklight::SolrResponse::Facets::FacetItem.new(:value => 'Value', :hits => 1234)])
- view.stub(:facet_field_names => [:facet_field_1],
+ allow(view).to receive_messages(:facet_field_names => [:facet_field_1],
:facet_limit_for => 10 )
@response = double()
- @response.stub(:facet_by_field_name).with(:facet_field_1) { @mock_display_facet_1 }
+ allow(@response).to receive(:facet_by_field_name).with(:facet_field_1) { @mock_display_facet_1 }
end
it "should have a header" do
- view.stub(:render_facet_partials => '')
+ allow(view).to receive_messages(:render_facet_partials => '')
render
expect(rendered).to have_selector('h4')
end
diff --git a/spec/views/catalog/_index_default.erb_spec.rb b/spec/views/catalog/_index_default.erb_spec.rb
index 395a16bd40..910a699e8e 100644
--- a/spec/views/catalog/_index_default.erb_spec.rb
+++ b/spec/views/catalog/_index_default.erb_spec.rb
@@ -21,24 +21,24 @@
@fname_4 = "four_field"
@document = double("solr_doc")
- @document.stub(:get).with(@fname_1, hash_including(:sep => nil)).and_return("val_1")
- @document.stub(:get).with(@fname_2, hash_including(:sep => nil)).and_return("val_2")
- @document.stub(:get).with(@fname_3, hash_including(:sep => nil)).and_return(nil)
- @document.stub(:get).with(@fname_4, hash_including(:sep => nil)).and_return("val_4")
+ allow(@document).to receive(:get).with(@fname_1, hash_including(:sep => nil)).and_return("val_1")
+ allow(@document).to receive(:get).with(@fname_2, hash_including(:sep => nil)).and_return("val_2")
+ allow(@document).to receive(:get).with(@fname_3, hash_including(:sep => nil)).and_return(nil)
+ allow(@document).to receive(:get).with(@fname_4, hash_including(:sep => nil)).and_return("val_4")
- @document.stub(:has?).with(@fname_1).and_return(true)
- @document.stub(:has?).with(@fname_2).and_return(true)
- @document.stub(:has?).with(@fname_3).and_return(false)
- @document.stub(:has?).with(@fname_4).and_return(true)
+ allow(@document).to receive(:has?).with(@fname_1).and_return(true)
+ allow(@document).to receive(:has?).with(@fname_2).and_return(true)
+ allow(@document).to receive(:has?).with(@fname_3).and_return(false)
+ allow(@document).to receive(:has?).with(@fname_4).and_return(true)
# cover any remaining fields in initalizer
- @document.stub(:[])
+ allow(@document).to receive(:[])
@flabel_1 = "One:"
@flabel_3 = "Three:"
@flabel_4 = "Four:"
- view.stub(:blacklight_config).and_return(@config)
+ allow(view).to receive(:blacklight_config).and_return(@config)
assigns[:document] = @document
@rendered = view.render_document_partial @document, :index
end
diff --git a/spec/views/catalog/_index_header_default.html.erb_spec.rb b/spec/views/catalog/_index_header_default.html.erb_spec.rb
index 3c0c828580..d3735b80c7 100644
--- a/spec/views/catalog/_index_header_default.html.erb_spec.rb
+++ b/spec/views/catalog/_index_header_default.html.erb_spec.rb
@@ -11,11 +11,11 @@
it "should render the document header" do
assign :response, double(:params => {})
- view.stub(:current_search_session).and_return nil
- view.stub(:search_session).and_return({})
- view.stub(:render_grouped_response?).and_return false
- view.stub(:blacklight_config).and_return(blacklight_config)
- view.stub(:render_bookmarks_control?).and_return false
+ allow(view).to receive(:current_search_session).and_return nil
+ allow(view).to receive(:search_session).and_return({})
+ allow(view).to receive(:render_grouped_response?).and_return false
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:render_bookmarks_control?).and_return false
render :partial => "catalog/index_header_default", :locals => {:document => document, :document_counter => 1}
expect(rendered).to have_selector('.document-counter', text: "2")
end
diff --git a/spec/views/catalog/_show_default.erb_spec.rb b/spec/views/catalog/_show_default.erb_spec.rb
index f16d779ad5..d1ef59c8e2 100644
--- a/spec/views/catalog/_show_default.erb_spec.rb
+++ b/spec/views/catalog/_show_default.erb_spec.rb
@@ -23,24 +23,24 @@
@fname_4 = "four_field"
@document = double("solr_doc")
- @document.stub(:get).with(@fname_1, hash_including(:sep => nil)).and_return("val_1")
- @document.stub(:get).with(@fname_2, hash_including(:sep => nil)).and_return("val_2")
- @document.stub(:get).with(@fname_3, hash_including(:sep => nil)).and_return(nil)
- @document.stub(:get).with(@fname_4, hash_including(:sep => nil)).and_return("val_4")
+ allow(@document).to receive(:get).with(@fname_1, hash_including(:sep => nil)).and_return("val_1")
+ allow(@document).to receive(:get).with(@fname_2, hash_including(:sep => nil)).and_return("val_2")
+ allow(@document).to receive(:get).with(@fname_3, hash_including(:sep => nil)).and_return(nil)
+ allow(@document).to receive(:get).with(@fname_4, hash_including(:sep => nil)).and_return("val_4")
- @document.stub(:'has?').with(@fname_1).and_return(true)
- @document.stub(:'has?').with(@fname_2).and_return(true)
- @document.stub(:'has?').with(@fname_3).and_return(false)
- @document.stub(:'has?').with(@fname_4).and_return(true)
+ allow(@document).to receive(:has?).with(@fname_1).and_return(true)
+ allow(@document).to receive(:has?).with(@fname_2).and_return(true)
+ allow(@document).to receive(:has?).with(@fname_3).and_return(false)
+ allow(@document).to receive(:has?).with(@fname_4).and_return(true)
# cover any remaining fields in initalizer
- @document.stub(:[])
+ allow(@document).to receive(:[])
@flabel_1 = "One:"
@flabel_3 = "Two:"
@flabel_4 = "Four:"
- view.stub(:blacklight_config).and_return(@config)
+ allow(view).to receive(:blacklight_config).and_return(@config)
assigns[:document] = @document
@rendered = view.render_document_partial @document, :show
end
diff --git a/spec/views/catalog/_show_sidebar.erb_spec.rb b/spec/views/catalog/_show_sidebar.erb_spec.rb
index 208a6f256e..51fb2a685a 100644
--- a/spec/views/catalog/_show_sidebar.erb_spec.rb
+++ b/spec/views/catalog/_show_sidebar.erb_spec.rb
@@ -6,15 +6,15 @@
before(:each) do
- view.stub(:blacklight_config).and_return(CatalogController.blacklight_config)
- view.stub(:has_user_authentication_provider?).and_return(false)
- view.stub(:current_search_session).and_return nil
- view.stub(:search_session).and_return({})
+ allow(view).to receive(:blacklight_config).and_return(CatalogController.blacklight_config)
+ allow(view).to receive(:has_user_authentication_provider?).and_return(false)
+ allow(view).to receive(:current_search_session).and_return nil
+ allow(view).to receive(:search_session).and_return({})
end
it "should show more-like-this titles in the sidebar" do
@document = SolrDocument.new :id => 1, :title_s => 'abc', :format => 'default'
- @document.stub(:more_like_this).and_return([SolrDocument.new({ 'id' => '2', 'title_display' => 'Title of MLT Document' })])
+ allow(@document).to receive(:more_like_this).and_return([SolrDocument.new({ 'id' => '2', 'title_display' => 'Title of MLT Document' })])
render
expect(rendered).to include_text("More Like This")
expect(rendered).to include_text("Title of MLT Document")
diff --git a/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb b/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
index 9346f31518..5fe0066384 100644
--- a/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
+++ b/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
@@ -7,7 +7,7 @@
end
before do
- view.stub(blacklight_config: blacklight_config)
+ allow(view).to receive_messages(blacklight_config: blacklight_config)
end
it "should render the pagination, sort, per page and view type controls" do
diff --git a/spec/views/catalog/_thumbnail_default.erb_spec.rb b/spec/views/catalog/_thumbnail_default.erb_spec.rb
index 33c0c2f5e5..5997682b95 100644
--- a/spec/views/catalog/_thumbnail_default.erb_spec.rb
+++ b/spec/views/catalog/_thumbnail_default.erb_spec.rb
@@ -18,10 +18,10 @@
before do
assign :response, double(:params => {})
- view.stub(:render_grouped_response?).and_return false
- view.stub(:blacklight_config).and_return(blacklight_config)
- view.stub(:current_search_session).and_return nil
- view.stub(:search_session).and_return({})
+ allow(view).to receive(:render_grouped_response?).and_return false
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:current_search_session).and_return nil
+ allow(view).to receive(:search_session).and_return({})
end
it "should render the thumbnail if the document has one" do
diff --git a/spec/views/catalog/_view_type_group.html.erb_spec.rb b/spec/views/catalog/_view_type_group.html.erb_spec.rb
index ba35d94049..18d8284304 100644
--- a/spec/views/catalog/_view_type_group.html.erb_spec.rb
+++ b/spec/views/catalog/_view_type_group.html.erb_spec.rb
@@ -7,16 +7,17 @@
end
before do
- view.stub(blacklight_config: blacklight_config)
- view.stub(:show_sort_and_per_page? => true)
+ allow(view).to receive_messages(how_sort_and_per_page?: true, blacklight_config: blacklight_config)
end
it "should not display the group when there's only one option" do
+ assign(:response, [])
render partial: 'catalog/view_type_group'
expect(rendered).to be_empty
end
it "should display the group" do
+ assign(:response, [double])
blacklight_config.configure do |config|
config.view.delete(:list)
config.view.a
@@ -32,6 +33,7 @@
it "should set the current view to 'active'" do
+ assign(:response, [double])
blacklight_config.configure do |config|
config.view.delete(:list)
config.view.a
diff --git a/spec/views/catalog/facet.html.erb_spec.rb b/spec/views/catalog/facet.html.erb_spec.rb
index 54cd5dd11a..d7b6d184c2 100644
--- a/spec/views/catalog/facet.html.erb_spec.rb
+++ b/spec/views/catalog/facet.html.erb_spec.rb
@@ -5,26 +5,26 @@
let(:blacklight_config) { Blacklight::Configuration.new }
before :each do
blacklight_config.add_facet_field 'xyz', label: "Facet title"
- view.stub(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
stub_template 'catalog/_facet_pagination.html.erb' => 'pagination'
assign :facet, blacklight_config.facet_fields['xyz']
assign :display_facet, display_facet
end
it "should have the facet title" do
- view.stub(:render_facet_limit)
+ allow(view).to receive(:render_facet_limit)
render
expect(rendered).to have_selector 'h3', text: "Facet title"
end
it "should render facet pagination" do
- view.stub(:render_facet_limit)
+ allow(view).to receive(:render_facet_limit)
render
expect(rendered).to have_content 'pagination'
end
it "should render the facet limit" do
- view.should_receive(:render_facet_limit).with(display_facet, layout: false)
+ allow(view).to receive(:render_facet_limit).with(display_facet, layout: false)
render
end
-end
\ No newline at end of file
+end
diff --git a/spec/views/catalog/index.atom.builder_spec.rb b/spec/views/catalog/index.atom.builder_spec.rb
index 6c4796d754..edd828ad35 100644
--- a/spec/views/catalog/index.atom.builder_spec.rb
+++ b/spec/views/catalog/index.atom.builder_spec.rb
@@ -29,8 +29,8 @@
# but okay.
params.merge!( @params )
- view.stub(:blacklight_config).and_return(@config)
- view.stub(:search_field_options_for_select).and_return([])
+ allow(view).to receive(:blacklight_config).and_return(@config)
+ allow(view).to receive(:search_field_options_for_select).and_return([])
render :template => 'catalog/index', :formats => [:atom]
diff --git a/spec/views/catalog/index.html.erb_spec.rb b/spec/views/catalog/index.html.erb_spec.rb
index b735563bf9..a687d8149d 100644
--- a/spec/views/catalog/index.html.erb_spec.rb
+++ b/spec/views/catalog/index.html.erb_spec.rb
@@ -4,8 +4,8 @@
describe "with no search parameters" do
before do
- view.stub(:has_search_parameters?).and_return(false)
- view.stub(:blacklight_config).and_return(Blacklight::Configuration.new)
+ allow(view).to receive(:has_search_parameters?).and_return(false)
+ allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new)
end
it "should render the sidebar and content panes" do
render
@@ -22,12 +22,12 @@
describe "with search parameters" do
before do
- view.stub(:has_search_parameters?).and_return(true)
+ allow(view).to receive(:has_search_parameters?).and_return(true)
stub_template "catalog/_results_pagination.html.erb" => ""
stub_template "catalog/_search_header.html.erb" => "header_content"
- view.stub(:blacklight_config).and_return(Blacklight::Configuration.new)
- view.stub(:render_opensearch_response_metadata).and_return("")
+ allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new)
+ allow(view).to receive(:render_opensearch_response_metadata).and_return("")
assign(:response, double(:empty? => true))
end
it "should render the search_header partial " do
diff --git a/spec/views/catalog/show.html.erb_spec.rb b/spec/views/catalog/show.html.erb_spec.rb
index 174786080d..c46531f777 100644
--- a/spec/views/catalog/show.html.erb_spec.rb
+++ b/spec/views/catalog/show.html.erb_spec.rb
@@ -11,14 +11,14 @@
end
before :each do
- view.stub(:has_user_authentication_provider? => false)
- view.stub(:render_document_sidebar_partial => "Sidebar")
+ allow(view).to receive_messages(:has_user_authentication_provider? => false)
+ allow(view).to receive_messages(:render_document_sidebar_partial => "Sidebar")
assign :document, document
- view.stub(:blacklight_config).and_return(blacklight_config)
+ allow(view).to receive(:blacklight_config).and_return(blacklight_config)
end
it "should set the @page_title" do
- view.stub(:document_show_html_title).and_return("Heading")
+ allow(view).to receive(:document_show_html_title).and_return("Heading")
render
page_title = view.instance_variable_get(:@page_title)
expect(page_title).to eq "Heading - Blacklight"
@@ -26,8 +26,8 @@
end
it "should include schema.org itemscope/type properties" do
- view.stub(:document_show_html_title).and_return("Heading")
- document.stub(:itemtype => 'some-item-type-uri')
+ allow(view).to receive(:document_show_html_title).and_return("Heading")
+ allow(document).to receive_messages(:itemtype => 'some-item-type-uri')
render
expect(rendered).to have_selector('div#document[@itemscope]')
@@ -35,7 +35,7 @@
end
it "should render the show_header and show partials by default" do
- view.stub(:render_grouped_response?).and_return(false)
+ allow(view).to receive(:render_grouped_response?).and_return(false)
stub_template "catalog/_show_header_default.html.erb" => "document_header"
stub_template "catalog/_show_default.html.erb" => "show_default"
@@ -47,7 +47,7 @@
it "should use the show.partials parameter to determine the partials to render" do
- view.stub(:render_grouped_response?).and_return(false)
+ allow(view).to receive(:render_grouped_response?).and_return(false)
blacklight_config.show.partials = ['a', 'b', 'c']
stub_template "catalog/_a_default.html.erb" => "a_partial"
stub_template "catalog/_b_default.html.erb" => "b_partial"