Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #58

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯/💯

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