-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commits are marked with [success/error] state depending on offence detection. If there are any offences in the code, the commit is marked with error state otherwise with success state. It is reflected at the end of PR in the check conclusion part.
- Loading branch information
Showing
4 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe GithubService do | ||
let(:repo) { "owner/repository" } | ||
let(:sha) { "b0e6911a4b7cc8dcf6aa4ed28244a1d5fb90d051" } | ||
let(:url) { "https://github.com/" } | ||
let(:num) { 42 } | ||
|
||
describe ".add_status" do | ||
let(:username) { "name" } | ||
|
||
before do | ||
stub_settings(Hash(:github_credentials => {:username => username})) | ||
end | ||
|
||
it "should create a success state (zero offenses)" do | ||
expect(described_class).to receive(:create_status).with(repo, sha, "success", Hash("context" => username, "target_url" => url, "description" => "Everything looks fine.")) | ||
|
||
described_class.add_status(repo, sha, url, :zero) | ||
end | ||
|
||
it "should create an success state (some offenses)" do | ||
expect(described_class).to receive(:create_status).with(repo, sha, "success", Hash("context" => username, "target_url" => url, "description" => "Some offenses detected.")) | ||
|
||
described_class.add_status(repo, sha, url, :warn) | ||
end | ||
|
||
it "should create an error state (at least one bomb offense)" do | ||
expect(described_class).to receive(:create_status).with(repo, sha, "error", Hash("context" => username, "target_url" => url, "description" => "Something went wrong.")) | ||
|
||
described_class.add_status(repo, sha, url, :bomb) | ||
end | ||
end | ||
|
||
describe ".add_comments" do | ||
let(:comment_in) { "input_comment" } | ||
let(:comments_in) { [comment_in, comment_in, comment_in] } | ||
let(:comment_out) { Hash("html_url"=> url) } | ||
|
||
it "should return an array of comments" do | ||
expect(described_class).to receive(:add_comment).with(repo, num, comment_in).and_return(comment_out).exactly(comments_in.count) | ||
expect(described_class.add_comments(repo, num, comments_in)).to match_array([comment_out, comment_out, comment_out]) | ||
end | ||
end | ||
|
||
describe ".replace_comments" do | ||
let(:comments_in) { %w(input_comment input_comment input_comment) } | ||
let(:comment_to_delete) { double("comment_to_delete", :id => "comment_id") } | ||
let(:comments_to_delete) { [comment_to_delete, comment_to_delete, comment_to_delete] } | ||
let(:comments_out) { [Hash("html_url"=> url), Hash("key"=> "value")] } | ||
|
||
it "should add commit status" do | ||
expect(described_class).to receive(:issue_comments).with(repo, num).and_return(comments_to_delete) | ||
expect(described_class).to receive(:delete_comments).with(repo, comments_to_delete.map(&:id)) | ||
expect(described_class).to receive(:add_comments).with(repo, num, comments_in).and_return(comments_out) | ||
expect(described_class).to receive(:add_status).with(repo, sha, url, true).once | ||
|
||
described_class.replace_comments(repo, num, comments_in, true, sha) { "something" } | ||
end | ||
end | ||
end |
44 changes: 44 additions & 0 deletions
44
spec/workers/commit_monitor_handlers/commit_range/rubocop_checker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe CommitMonitorHandlers::CommitRange::RubocopChecker do | ||
describe "#replace_rubocop_comments" do | ||
let(:num) { 42 } | ||
let(:repo) { "owner/repository" } | ||
let(:comments) { %w(comment1 comment2) } | ||
let(:sha) { "b0e6911a4b7cc8dcf6aa4ed28244a1d5fb90d051" } | ||
let(:commits) { ["x", "y", sha] } | ||
|
||
let(:results_no_status) { Hash("files"=> [Hash("offenses"=> [Hash("severity"=>"warn"), Hash("severity"=>"info")]), Hash("offenses"=> [Hash("severity"=>"unknown"), Hash("severity"=>"info")])]) } | ||
let(:results_red_status) { Hash("files"=> [Hash("offenses"=> [Hash("severity"=>"warn"), Hash("severity"=>"error")]), Hash("offenses"=> [Hash("severity"=>"fatal"), Hash("severity"=>"info")])]) } | ||
let(:results_green_status) { Hash("files"=> [Hash("offenses"=> []), Hash("offenses"=> [])]) } | ||
|
||
before do | ||
allow(subject).to receive(:fq_repo_name).and_return(repo) | ||
allow(subject).to receive(:pr_number).and_return(num) | ||
allow(subject).to receive(:rubocop_comments).and_return(comments) | ||
allow(subject).to receive(:commits).and_return(commits) | ||
end | ||
|
||
after do | ||
subject.send(:replace_rubocop_comments) | ||
end | ||
|
||
it "should call replace_comments with :zero (green - success) status" do | ||
allow(subject).to receive(:results).and_return(results_green_status) | ||
|
||
expect(GithubService).to receive(:replace_comments).with(repo, num, comments, :zero, sha).once | ||
end | ||
|
||
it "should call replace_comments with :bomb (red - error) status" do | ||
allow(subject).to receive(:results).and_return(results_red_status) | ||
|
||
expect(GithubService).to receive(:replace_comments).with(repo, num, comments, :bomb, sha).once | ||
end | ||
|
||
it "should call replace_comments with :warn (green - success) status" do | ||
allow(subject).to receive(:results).and_return(results_no_status) | ||
|
||
expect(GithubService).to receive(:replace_comments).with(repo, num, comments, :warn, sha).once | ||
end | ||
end | ||
end |