Skip to content

Commit

Permalink
Refactor test to meet rubocop expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdonarski committed Oct 4, 2023
1 parent 6d34140 commit 94b4157
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions spec/models/spree/admin/tabs/tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ module Spree
module Admin
describe Tabs::Tab, type: :model do
let(:tab) { described_class.new(config) }
let(:config_base) do
let(:config) do
{
icon_name: 'cart-check.svg',
name: 'Cart',
url: '/cart',
classes: 'nav-link',
partial_name: :cart
partial_name: :cart,
availability_check: check,
active_check: check,
completed_check: check
}
end
let(:additional_config) { {} }
let(:config) do
config_base.merge(additional_config)
end
let(:check) { nil }

describe '#icon_name' do
subject { tab.icon_name }
Expand Down Expand Up @@ -63,11 +63,7 @@ module Admin
end

context 'when availability check returns false' do
let(:additional_config) do
{
availability_check: ->(_ability, _resource) { false }
}
end
let(:check) { ->(_ability, _resource) { false } }

it 'returns false' do
expect(subject).to be(false)
Expand All @@ -79,11 +75,7 @@ module Admin
subject { tab.active?(current_tab) }

context 'when active check returns true' do
let(:additional_config) do
{
active_check: ->(_current_tab, _text) { true }
}
end
let(:check) { ->(_current_tab, _text) { true } }
let(:current_tab) { config[:partial_name] }

it 'returns true' do
Expand All @@ -92,11 +84,7 @@ module Admin
end

context 'when active check returns false' do
let(:additional_config) do
{
active_check: ->(_current_tab, _text) { false }
}
end
let(:check) { ->(_current_tab, _text) { false } }
let(:current_tab) { 'non-matching' }

it 'returns false' do
Expand All @@ -116,11 +104,7 @@ module Admin
end

context 'when complete check returns false' do
let(:additional_config) do
{
completed_check: ->(_resource) { false }
}
end
let(:check) { ->(_resource) { false } }

it 'returns false' do
expect(subject).to be(false)
Expand Down

0 comments on commit 94b4157

Please sign in to comment.