Skip to content

Commit 65a292a

Browse files
committed
Add specs for validating css for color schemes
1 parent 781f2c8 commit 65a292a

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

spec/rails_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require "rspec/rails"
1313
# Add additional requires below this line. Rails is not loaded until this point!
1414
require "phlex/testing/view_helper"
15+
require "w3c_validators"
1516

1617
# Requires supporting ruby files with custom matchers and macros, etc, in
1718
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are

spec/requests/color_schemes_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,18 @@
3131

3232
expect(response).to have_http_status(:ok)
3333
end
34+
35+
it "renders color scheme as css" do
36+
color_scheme = FactoryBot.create(:color_scheme)
37+
38+
get color_scheme_path(color_scheme, format: :css)
39+
40+
expect(response).to have_http_status(:ok)
41+
42+
validator = W3CValidators::CSSValidator.new
43+
validator_results = validator.validate_text(response.body) # W3CValidators::Results
44+
45+
expect(validator_results.is_valid?).to be(true), "Expected CSS to be valid, but got: #{validator_results.errors.map(&:to_s).join(", ")}"
46+
end
3447
end
3548
end

spec/requests/feed_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
require "rails_helper"
22

3-
require "w3c_validators"
4-
53
RSpec.describe "Feed", type: :request do
64
let(:curated_colors) do
75
FactoryBot.create_list(:color_scheme, 3)

spec/support/webmock_vcr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
allow_localhost: true,
1515
allow: [
1616
"chromedriver.storage.googleapis.com",
17-
"validator.w3.org"
17+
%r{w3.org/}
1818
]
1919
)
2020
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "rails_helper"
2+
3+
RSpec.describe ColorSchemes::Css do
4+
describe "#call" do
5+
it "renders valid css" do
6+
component = described_class.new(color_scheme: FactoryBot.build(:color_scheme))
7+
8+
validator = W3CValidators::CSSValidator.new
9+
validator_results = validator.validate_text(component.call)
10+
11+
expect(validator_results.is_valid?).to be(true), "Expected feed to be valid, but got: #{validator_results.errors.map(&:to_s).join(", ")}"
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)