Skip to content

Commit

Permalink
Merge pull request #3193 from projectblacklight/rubocop-capybara
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Jun 13, 2024
2 parents 855ad63 + 4f7dab1 commit bea5b57
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 48 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require:
- rubocop-rspec
- rubocop-rspec_rails
- rubocop-rails
- rubocop-factory_bot

inherit_from:
- .rubocop_todo.yml
Expand Down
3 changes: 3 additions & 0 deletions blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Gem::Specification.new do |s|
s.add_development_dependency "rubocop", '~> 1.0'
s.add_development_dependency "rubocop-rails"
s.add_development_dependency "rubocop-rspec"
s.add_development_dependency "rubocop-capybara"
s.add_development_dependency "rubocop-rspec_rails"
s.add_development_dependency "rubocop-factory_bot"
s.add_development_dependency "i18n-tasks"
s.add_development_dependency "solr_wrapper"
end
2 changes: 1 addition & 1 deletion spec/controllers/blacklight/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it "creates a path object" do
expect(subject).to be_kind_of Blacklight::SearchState
expect(subject).to be_a Blacklight::SearchState
expect(subject.params).to eq raw_params
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,10 @@ def export_as_mock
it "is successful" do
get :facet, params: { id: 'format' }
expect(response).to be_successful
expect(assigns[:response]).to be_kind_of Blacklight::Solr::Response
expect(assigns[:facet]).to be_kind_of Blacklight::Configuration::FacetField
expect(assigns[:display_facet]).to be_kind_of Blacklight::Solr::Response::Facets::FacetField
expect(assigns[:pagination]).to be_kind_of Blacklight::Solr::FacetPaginator
expect(assigns[:response]).to be_a Blacklight::Solr::Response
expect(assigns[:facet]).to be_a Blacklight::Configuration::FacetField
expect(assigns[:display_facet]).to be_a Blacklight::Solr::Response::Facets::FacetField
expect(assigns[:pagination]).to be_a Blacklight::Solr::FacetPaginator
end
end

Expand All @@ -638,7 +638,7 @@ def export_as_mock

expect(response).to be_successful

expect(assigns[:facet]).to be_kind_of Blacklight::Configuration::FacetField
expect(assigns[:facet]).to be_a Blacklight::Configuration::FacetField
expect(assigns[:facet].key).to eq 'params_key'
expect(assigns[:facet].field).to eq 'format'

Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/blacklight/facets_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it 'wraps the facet data in a presenter' do
presenter = helper.facet_field_presenter(facet_config, display_facet)
expect(presenter).to be_a_kind_of Blacklight::FacetFieldPresenter
expect(presenter).to be_a Blacklight::FacetFieldPresenter
expect(presenter.facet_field).to eq facet_config
expect(presenter.display_facet).to eq display_facet
expect(presenter.view_context).to eq helper
Expand All @@ -23,7 +23,7 @@
stub_const('SomePresenter', Class.new(Blacklight::FacetFieldPresenter))
facet_config.presenter = SomePresenter
presenter = helper.facet_field_presenter(facet_config, display_facet)
expect(presenter).to be_a_kind_of SomePresenter
expect(presenter).to be_a SomePresenter
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

describe "#deep_dup" do
it "preserves the current class" do
expect(described_class.new(described_class).deep_dup).to be_a_kind_of described_class
expect(described_class.new(described_class).deep_dup).to be_a described_class
end

it "preserves the default proc" do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/blacklight/open_struct_with_hash_access_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

it "exposes the internal hash table" do
expect(@h.to_h).to be_a_kind_of(Hash)
expect(@h.to_h).to be_a(Hash)
expect(@h.to_h[:a]).to eq 1
end

Expand Down
24 changes: 12 additions & 12 deletions spec/models/blacklight/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

describe "initialization" do
it "is an OpenStructWithHashAccess" do
expect(config).to be_a_kind_of Blacklight::OpenStructWithHashAccess
expect(config).to be_a Blacklight::OpenStructWithHashAccess
end

it "accepts a block for configuration" do
Expand All @@ -30,22 +30,22 @@

describe "defaults" do
it "has a hash of default rsolr query parameters" do
expect(config.default_solr_params).to be_a_kind_of Hash
expect(config.default_solr_params).to be_a Hash
end

it "has openstruct values for show and index parameters" do
expect(config.show).to be_a_kind_of OpenStruct
expect(config.index).to be_a_kind_of OpenStruct
expect(config.show).to be_a OpenStruct
expect(config.index).to be_a OpenStruct
end

it "has ordered hashes for field configuration" do
expect(config.facet_fields).to be_a_kind_of Hash
expect(config.index_fields).to be_a_kind_of Hash
expect(config.show_fields).to be_a_kind_of Hash
expect(config.search_fields).to be_a_kind_of Hash
expect(config.show_fields).to be_a_kind_of Hash
expect(config.search_fields).to be_a_kind_of Hash
expect(config.sort_fields).to be_a_kind_of Hash
expect(config.facet_fields).to be_a Hash
expect(config.index_fields).to be_a Hash
expect(config.show_fields).to be_a Hash
expect(config.search_fields).to be_a Hash
expect(config.show_fields).to be_a Hash
expect(config.search_fields).to be_a Hash
expect(config.sort_fields).to be_a Hash
end
end

Expand Down Expand Up @@ -197,7 +197,7 @@
config.add_my_custom_facet_field 'qwerty', label: "asdf"
end

expect(config.my_custom_facet_fields['qwerty']).to be_a_kind_of(Blacklight::Configuration::FacetField)
expect(config.my_custom_facet_fields['qwerty']).to be_a(Blacklight::Configuration::FacetField)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/models/blacklight/solr/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class MockDocument
end

it "returns an array even for a single-value field" do
expect(@doc1.to_semantic_values[:title]).to be_kind_of(Array)
expect(@doc1.to_semantic_values[:title]).to be_a(Array)
end

it "returns complete array for a multi-value field" do
Expand Down Expand Up @@ -290,7 +290,7 @@ class MockDocument

it "plucks the MoreLikeThis results from the Solr Response" do
expect(result).to have(1).item
expect(result.first).to be_a_kind_of(MockDocument)
expect(result.first).to be_a(MockDocument)
expect(result.first.id).to eq 'abc'
expect(result.first.solr_response).to eq response
end
Expand Down
26 changes: 13 additions & 13 deletions spec/models/blacklight/solr/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
blacklight_config.document_solr_path = 'abc'
blacklight_config.solr_path = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('abc', anything).and_return(mock_response)
expect(subject.find("123")).to be_a_kind_of Blacklight::Solr::Response
expect(subject.find("123")).to be_a Blacklight::Solr::Response
end

it "uses a default :qt param" do
allow(subject.connection).to receive(:send_and_receive).with('get', hash_including(params: hash_including(ids: '123'))).and_return(mock_response)
expect(subject.find("123", {})).to be_a_kind_of Blacklight::Solr::Response
expect(subject.find("123", {})).to be_a Blacklight::Solr::Response
end

context "without a document solr path configured" do
Expand All @@ -40,7 +40,7 @@
it "uses the default solr path" do
blacklight_config.solr_path = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('xyz', anything).and_return(mock_response)
expect(subject.find("123")).to be_a_kind_of Blacklight::Solr::Response
expect(subject.find("123")).to be_a Blacklight::Solr::Response
end
end

Expand All @@ -53,48 +53,48 @@
it "uses the provided :qt param" do
blacklight_config.document_solr_request_handler = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { id: '123', qt: 'abc' })).and_return(mock_response)
expect(subject.find("123", qt: 'abc')).to be_a_kind_of Blacklight::Solr::Response
expect(subject.find("123", qt: 'abc')).to be_a Blacklight::Solr::Response
end

it "uses the :qt parameter from the default_document_solr_params" do
blacklight_config.default_document_solr_params[:qt] = 'abc'
blacklight_config.document_solr_request_handler = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { id: '123', qt: 'abc' })).and_return(mock_response)
expect(subject.find("123")).to be_a_kind_of Blacklight::Solr::Response
expect(subject.find("123")).to be_a Blacklight::Solr::Response
end
end

it "preserves the class of the incoming params" do
doc_params = ActiveSupport::HashWithIndifferentAccess.new
allow(subject.connection).to receive(:send_and_receive).with('get', anything).and_return(mock_response)
response = subject.find("123", doc_params)
expect(response).to be_a_kind_of Blacklight::Solr::Response
expect(response.params).to be_a_kind_of ActiveSupport::HashWithIndifferentAccess
expect(response).to be_a Blacklight::Solr::Response
expect(response.params).to be_a ActiveSupport::HashWithIndifferentAccess
end
end

describe "#search" do
it "uses the search-specific solr path" do
blacklight_config.solr_path = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('xyz', anything).and_return(mock_response)
expect(subject.search({})).to be_a_kind_of Blacklight::Solr::Response
expect(subject.search({})).to be_a Blacklight::Solr::Response
end

it "uses the default solr path" do
allow(subject.connection).to receive(:send_and_receive).with('select', anything).and_return(mock_response)
expect(subject.search({})).to be_a_kind_of Blacklight::Solr::Response
expect(subject.search({})).to be_a Blacklight::Solr::Response
end

it "uses a default :qt param" do
blacklight_config.qt = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { qt: 'xyz' })).and_return(mock_response)
expect(subject.search({})).to be_a_kind_of Blacklight::Solr::Response
expect(subject.search({})).to be_a Blacklight::Solr::Response
end

it "uses the provided :qt param" do
blacklight_config.qt = 'xyz'
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { qt: 'abc' })).and_return(mock_response)
expect(subject.search(qt: 'abc')).to be_a_kind_of Blacklight::Solr::Response
expect(subject.search(qt: 'abc')).to be_a Blacklight::Solr::Response
end

it "preserves the class of the incoming params" do
Expand All @@ -103,8 +103,8 @@
allow(subject.connection).to receive(:send_and_receive).with('select', anything).and_return(mock_response)

response = subject.search(search_params)
expect(response).to be_a_kind_of Blacklight::Solr::Response
expect(response.params).to be_a_kind_of ActiveSupport::HashWithIndifferentAccess
expect(response).to be_a Blacklight::Solr::Response
expect(response.params).to be_a ActiveSupport::HashWithIndifferentAccess
end

it "calls send_and_receive with params returned from request factory method" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/blacklight/solr/response/facets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def facet_counts
it "converts the query facets into a double RSolr FacetField" do
field = subject.aggregations['my_query_facet_field']

expect(field).to be_a_kind_of Blacklight::Solr::Response::Facets::FacetField
expect(field).to be_a Blacklight::Solr::Response::Facets::FacetField

expect(field.name).to eq 'my_query_facet_field'
expect(field.items.size).to eq 3
Expand Down Expand Up @@ -316,7 +316,7 @@ def facet_counts
it "converts the pivot facet into a double RSolr FacetField" do
field = subject.aggregations['my_pivot_facet_field']

expect(field).to be_a_kind_of Blacklight::Solr::Response::Facets::FacetField
expect(field).to be_a Blacklight::Solr::Response::Facets::FacetField

expect(field.name).to eq 'my_pivot_facet_field'

Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/solr/response/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
describe "#docs" do
it "is a list of SolrDocuments" do
subject.docs.each do |doc|
expect(doc).to be_a_kind_of SolrDocument
expect(doc).to be_a SolrDocument
end

expect(subject.docs.first.id).to eq 1
Expand Down
4 changes: 2 additions & 2 deletions spec/models/blacklight/solr/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
if Kaminari.config.respond_to? :max_pages
expect(r.max_pages).to be_nil
end
expect(r).to be_a_kind_of Kaminari::PageScopeMethods
expect(r).to be_a Kaminari::PageScopeMethods
end

describe "FacetItem" do
Expand All @@ -101,7 +101,7 @@

expect(item.hits).to eq 15
expect(item.value).to eq 'value'
expect(item).to be_a_kind_of(OpenStruct)
expect(item).to be_a(OpenStruct)
end

it "provides a label accessor" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@

subject.add_facet_fq_to_solr(solr_parameters)

expect(solr_parameters[:fq]).to be_a_kind_of Array
expect(solr_parameters[:fq]).to be_a Array
end

context "facet not defined in config" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/bookmark_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

describe "#document" do
it "is a SolrDocument with just an id field" do
expect(subject.document).to be_a_kind_of SolrDocument
expect(subject.document).to be_a SolrDocument
expect(subject.document.id).to eq 'u001'
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/presenters/blacklight/document_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@

describe '#thumbnail' do
it 'returns a thumbnail presenter' do
expect(presenter.thumbnail).to be_a_kind_of(Blacklight::ThumbnailPresenter)
expect(presenter.thumbnail).to be_a(Blacklight::ThumbnailPresenter)
end

it 'use the configured thumbnail presenter' do
custom_presenter_class = Class.new(Blacklight::ThumbnailPresenter)
blacklight_config.index.thumbnail_presenter = custom_presenter_class

expect(presenter.thumbnail).to be_a_kind_of custom_presenter_class
expect(presenter.thumbnail).to be_a custom_presenter_class
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/services/blacklight/search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
end

it "returns a grouped response" do
expect(service.search_results).to be_a_kind_of Blacklight::Solr::Response::GroupResponse
expect(service.search_results).to be_a Blacklight::Solr::Response::GroupResponse
end
end

Expand All @@ -93,7 +93,7 @@

it "returns a grouped response" do
solr_response = service.search_results
expect(solr_response).to be_a_kind_of Blacklight::Solr::Response::GroupResponse
expect(solr_response).to be_a Blacklight::Solr::Response::GroupResponse
expect(solr_response.group_field).to eq "title_si"
end
end
Expand Down

0 comments on commit bea5b57

Please sign in to comment.