Skip to content

Commit

Permalink
Add HamlLint integration test
Browse files Browse the repository at this point in the history
This caught one thing we forgot to change in the previous refactor.

Also, extract the common test bolierplate into a shared example.
  • Loading branch information
Greg Lazarev committed Jun 8, 2016
1 parent 6afe00a commit 79ffc01
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 57 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
2 changes: 1 addition & 1 deletion lib/jobs/haml_review_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.perform(attributes)
Runner.call(
attributes: attributes,
linter_class: Linters::HamlLint::Linter,
config_filename: "haml.yml",
default_config_filename: "haml.yml",
)
end
end
4 changes: 2 additions & 2 deletions lib/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.call(*args)
new(*args).call
end

# This job receives the following arguments
# The attributes are passed from the job and contain the following:
# - filename
# - content
# - config
Expand Down Expand Up @@ -48,7 +48,7 @@ def complete_file_review(violations)
Resque.enqueue(
CompletedFileReviewJob,
commit_sha: attributes.fetch("commit_sha"),
filename: file.path,
filename: attributes.fetch("filename"),
patch: attributes.fetch("patch"),
pull_request_number: attributes.fetch("pull_request_number"),
violations: violations,
Expand Down
53 changes: 0 additions & 53 deletions spec/jobs/scss_review_job_spec.rb

This file was deleted.

15 changes: 15 additions & 0 deletions spec/lib/jobs/haml_review_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "jobs/haml_review_job"

RSpec.describe HamlReviewJob do
it_behaves_like(
"a linter",
content: "%div\n #main",
filename: "test.haml",
violations: [
{
line: 2,
message: "Files should end with a trailing newline",
}
],
)
end
12 changes: 12 additions & 0 deletions spec/lib/jobs/scss_review_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "jobs/scss_review_job"

RSpec.describe ScssReviewJob do
it_behaves_like(
"a linter",
content: "$color: #aaa\n",
filename: "test.scss",
violations: [
{ line: 1, message: "Declaration should be terminated by a semicolon" }
],
)
end
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$: << File.expand_path(".")

require "byebug"

$: << File.expand_path(".")
Dir["./spec/support/**/*.rb"].sort.each { |file| require file }

ENV["RACK_ENV"] = "test"
ENV["REDIS_URL"] = "redis://rediswoohoo:[email protected]:12345/"
23 changes: 23 additions & 0 deletions spec/support/shared_examples/linter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.shared_examples "a linter" do |args|
it "enqueues a job with violations" do
attributes = {
"filename" => args.fetch(:filename),
"content" => args.fetch(:content),
"commit_sha" => "anything",
"patch" => "",
"pull_request_number" => "1",
}
allow(Resque).to receive(:enqueue)

described_class.perform(attributes)

expect(Resque).to have_received(:enqueue).with(
CompletedFileReviewJob,
commit_sha: attributes["commit_sha"],
filename: attributes["filename"],
patch: attributes["patch"],
pull_request_number: attributes["pull_request_number"],
violations: args.fetch(:violations),
)
end
end

0 comments on commit 79ffc01

Please sign in to comment.