Skip to content

Commit

Permalink
Merge pull request #58 from rubocop/improve-test-coverage
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
bquorning authored Feb 12, 2025
2 parents 2ffe982 + 7ae719f commit cc58bde
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SimpleCov.start do
enable_coverage :branch
minimum_coverage line: 95.17, branch: 85.13
minimum_coverage line: 100, branch: 100
add_filter '/spec/'
add_filter '/vendor/bundle/'
end
8 changes: 4 additions & 4 deletions lib/rubocop/cop/rspec_rails/http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def checker_class
NumericStyleChecker
when :be_status
BeStatusStyleChecker
else
# :nocov:
:noop
# :nocov:
end
end

Expand All @@ -126,10 +130,6 @@ def message
end
end

def autocorrectable?
true
end

def current
offense_range.source
end
Expand Down
6 changes: 6 additions & 0 deletions lib/rubocop/cop/rspec_rails/inferred_spec_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def autocorrect(corrector, node)

# @param [RuboCop::AST::Node] node
# @return [Parser::Source::Range]
# rubocop:disable Metrics/MethodLength
def remove_range(node)
if node.left_sibling
node.source_range.with(
Expand All @@ -102,8 +103,13 @@ def remove_range(node)
node.source_range.with(
end_pos: node.right_sibling.source_range.begin_pos
)
else
# :nocov:
:noop
# :nocov:
end
end
# rubocop:enable Metrics/MethodLength

# @param [RuboCop::AST::PairNode] node
# @return [RuboCop::AST::Node]
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/rspec_rails/minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class BasicAssertion
attr_reader :expected, :actual, :failure_message

def self.minitest_assertion
# :nocov:
raise NotImplementedError
# :nocov:
end

def initialize(expected, actual, failure_message)
Expand All @@ -62,7 +64,9 @@ def negated?(node)
end

def assertion
# :nocov:
raise NotImplementedError
# :nocov:
end
end

Expand Down
12 changes: 12 additions & 0 deletions lib/rubocop/cop/rspec_rails/negation_be_valid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def offense?(node)
be_invalid?(node)
when :be_invalid
not_to?(node)
else
# :nocov:
:noop
# :nocov:
end
end

Expand All @@ -81,6 +85,10 @@ def replaced_runner
'not_to'
when :be_invalid
'to'
else
# :nocov:
:noop
# :nocov:
end
end

Expand All @@ -90,6 +98,10 @@ def replaced_matcher
'be_valid'
when :be_invalid
'be_invalid'
else
# :nocov:
:noop
# :nocov:
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/rubocop/cop/rspec_rails/http_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@

expect_no_corrections
end

it 'registers no offense when Rack is not loaded' do
hide_const('Rack')

expect_no_offenses(<<~RUBY)
it { is_expected.to have_http_status(404) }
RUBY
end
end

context 'when EnforcedStyle is `numeric`' do
Expand Down Expand Up @@ -163,6 +171,14 @@
RUBY
end
end

it 'registers no offense when Rack is not loaded' do
hide_const('Rack')

expect_no_offenses(<<~RUBY)
it { is_expected.to have_http_status(:not_found) }
RUBY
end
end

context 'when EnforcedStyle is `be_status`' do
Expand Down Expand Up @@ -287,5 +303,13 @@
RUBY
end
end

it 'registers no offense when Rack is not loaded' do
hide_const('Rack')

expect_no_offenses(<<~RUBY)
it { is_expected.to have_http_status(:not_found) }
RUBY
end
end
end

0 comments on commit cc58bde

Please sign in to comment.