Skip to content

Commit

Permalink
raise error when same branches are compared
Browse files Browse the repository at this point in the history
  • Loading branch information
rishijain committed Oct 17, 2023
1 parent 1d20e4f commit 7ec088e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [CHANGE] Fix test warning related to `cucumber_opts` declaration (by [@faisal][])
* [BUGFIX] Stop using long-deprecated MiniTest module name, removed in 5.19.0 (by [@faisal][])
* [CHANGE] Disable VERBOSE warnings in test stubs (by [@fbuys][])
* [BUGFIX] Raise error when the same branches are compared (by [@rishijain][])

# v4.8.1 / 2023-05-17 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.8.0...v4.8.1)

Expand Down
4 changes: 4 additions & 0 deletions lib/rubycritic/commands/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def initialize(options)
end

def execute
if Config.send(:base_branch) == Config.send(:feature_branch)
raise('The branch you are on and are comparing with are the same.
Please switch to a different branch or choose a different branch to compare.')
end
compare_branches
status_reporter.score = Config.feature_branch_score
status_reporter
Expand Down
17 changes: 17 additions & 0 deletions test/lib/rubycritic/commands/compare_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ def abort(str); end
RubyCritic::SourceControlSystem::Git.stubs(:modified_files).returns('test/samples/compare_file.rb')
end

describe 'comparing the branches with the compare option' do
context 'when same branches are compared' do
it 'it aborts with the error message' do
options = ['-b', 'feature_branch']
options = RubyCritic::Cli::Options.new(options).parse.to_h
RubyCritic::Config.set(options)
comparison = RubyCritic::Command::Compare.new(options)

assert_raises('The branch you are on and are comparing with are the same.
Please switch to a different branch or choose a different branch to compare.') do
comparison.execute
end
end
end
end

describe 'comparing the same file for two different branches' do
after do
# clear file contents after tests
Expand Down Expand Up @@ -65,6 +81,7 @@ def abort(str); end
options = ['-b', 'feature_branch', '-t', '0', 'test/samples/compare_file.rb']
options = RubyCritic::Cli::Options.new(options).parse.to_h
RubyCritic::Config.set(options)
RubyCritic::Config.set(base_branch: 'base_branch')
copy_proc = proc do |_|
FileUtils.cp 'test/samples/base_branch_file.rb', 'test/samples/compare_file.rb'
end
Expand Down

0 comments on commit 7ec088e

Please sign in to comment.