Skip to content

Commit

Permalink
Clean up console warnings when running tests (ViewComponent#1933)
Browse files Browse the repository at this point in the history
* use Ruby 3.2.2

* update yard dev dependency to latest

* Reduce noise in tests by turning off warnings

* appease YARD warning for including Rails routes, which are dynamic

* Resolve assert_nil warning from Minitest

* fix param name error in YARD comment

* silence YARD output in tests

* Fix YARD errors

* add CHANGELOG entry

* appease Standard

* include sha in artifact upload filename

* Turn off warnings for specific dependencies

* standard

* lock to pre-v4 upload-artifact action

* fix version number

* use specific version of checkout action

---------

Co-authored-by: Joel Hawksley <[email protected]>
Co-authored-by: Joel Hawksley <[email protected]>
  • Loading branch information
3 people authored and claudiob committed Jan 3, 2024
1 parent 22d6417 commit f5a9a9c
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 18 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4.1.1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
ruby_version: "3.2"
mode: "capture_patch_disabled"
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4.1.1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -80,7 +80,7 @@ jobs:
RAILS_VERSION: ${{ matrix.rails_version }}
CAPTURE_PATCH_ENABLED: ${{ matrix.mode == 'capture_patch_enabled' && 'true' || 'false' }}
- name: Upload coverage results
uses: actions/upload-artifact@master
uses: actions/upload-artifact@v3.1.3
if: always()
with:
name: simplecov-resultset-rails${{matrix.rails_version}}-ruby${{matrix.ruby_version}}
Expand All @@ -89,11 +89,11 @@ jobs:
name: Test compatibility with Primer ViewComponents (main)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4.1.1
with:
repository: 'primer/view_components'
path: 'primer_view_components'
- uses: actions/checkout@master
- uses: actions/checkout@v4.1.1
with:
path: 'view_component'
- name: Setup Ruby
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4.1.1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/test/sandbox/log/*
/test/tmp/*
/.yardoc
/_yardoc/

## Specific to RubyMotion:
.dat*
Expand All @@ -29,8 +28,6 @@ build-iPhoneOS/
build-iPhoneSimulator/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 3.0.3
ruby 3.2.2
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem "rspec-rails", "~> 5"
group :test do
gem "cuprite", "~> 0.15"
gem "puma", "~> 6"
gem "warning"

gem "selenium-webdriver", "4.9.0" # 4.9.1 requires Ruby 3+
end
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
warning (1.3.0)
webrick (1.8.1)
websocket (1.2.9)
websocket-driver (0.7.6)
Expand Down Expand Up @@ -347,7 +348,8 @@ DEPENDENCIES
sprockets-rails (~> 3.4.2)
standard (~> 1)
view_component!
yard (~> 0.9.25)
warning
yard (~> 0.9.34)
yard-activesupport-concern (~> 0.0.1)

BUNDLED WITH
Expand Down
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ end
namespace :docs do
# Build api.md documentation page from YARD comments.
task :build do
YARD::Rake::YardocTask.new
YARD::Rake::YardocTask.new do |t|
t.options = ["--no-output"]
end

puts "Building YARD documentation."

Rake::Task["yard"].execute
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 5

## main

* Resolve console warnings when running test suite.

*Joel Hawksley*

* Fix spelling in a local variable.

*Olle Jonsson*
Expand Down
16 changes: 15 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ with_controller_class(UsersController) do
end
```

### `#with_request_url(path, host: nil)`
### `#with_request_url(full_path, host: nil, method: nil)`

Set the URL of the current request (such as when using request-dependent path helpers):

Expand All @@ -374,6 +374,14 @@ with_request_url("/users/42", host: "app.example.com") do
end
```

To specify a request method, pass the method param:

```ruby
with_request_url("/users/42", method: "POST") do
render_inline(MyComponent.new)
end
```

### `#with_variant(variant)`

Set the Action Pack request variant for the given block:
Expand Down Expand Up @@ -519,3 +527,9 @@ ViewComponent SystemTest controller must only be called in a test environment fo
`#translate` can't be used during initialization as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.

It's sometimes possible to fix this issue by moving code dependent on `#translate` to a [`#before_render` method](https://viewcomponent.org/api.html#before_render--void).

### `UncountableSlotNameError`

COMPONENT declares a slot named SLOT_NAME, which is an uncountable word

To fix this issue, choose a different name.
1 change: 1 addition & 0 deletions lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def helpers
end

if ::Rails.env.development? || ::Rails.env.test?
# @private
def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToMissing
super
rescue => e # rubocop:disable Style/RescueStandardError
Expand Down
6 changes: 5 additions & 1 deletion lib/view_component/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

module ViewComponent # :nodoc:
class Preview
include Rails.application.routes.url_helpers if defined?(Rails.application.routes.url_helpers)
if defined?(Rails.application.routes.url_helpers)
# Workaround from https://stackoverflow.com/questions/20853526/make-yard-ignore-certain-class-extensions to appease YARD
send(:include, Rails.application.routes.url_helpers)
end

include ActionView::Helpers::TagHelper
include ActionView::Helpers::AssetTagHelper
extend ActiveSupport::DescendantsTracker
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def with_controller_class(klass)
# end
# ```
#
# @param path [String] The path to set for the current request.
# @param full_path [String] The path to set for the current request.
# @param host [String] The host to set for the current request.
# @param method [String] The request method to set for the current request.
def with_request_url(full_path, host: nil, method: nil)
Expand Down
8 changes: 8 additions & 0 deletions test/sandbox/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# frozen_string_literal: true

require "warning"

# Use https://github.com/jeremyevans/ruby-warning
# to restrict warnings outside our control
["mail", "activesupport", "yard"].each do |gem_name|
Warning.ignore(//, /.*gems\/#{gem_name}-.*/)
end

Sandbox::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

Expand Down
7 changes: 6 additions & 1 deletion test/sandbox/test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def test_templates_parses_all_types_of_paths

templates.each_with_index do |template, index|
assert_equal(template[:path], file_path[index])
assert_equal(template[:variant], expected[index][:variant])
if expected[index][:variant].nil?
# Minitest requires using #assert_nil if asserting nil!
assert_nil(template[:variant])
else
assert_equal(template[:variant], expected[index][:variant])
end
assert_equal(template[:handler], expected[index][:handler])
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/sandbox/test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def test_defaults_are_correct
def test_all_methods_are_documented
require "yard"
require "rake"
YARD::Rake::YardocTask.new
YARD::Rake::YardocTask.new do |t|
t.options = ["--no-output", "--no-stats", "--no-progress"]
end
Rake::Task["yard"].execute
configuration_methods_to_document = YARD::RegistryStore.new.tap do |store|
store.load!(".yardoc")
Expand Down
2 changes: 1 addition & 1 deletion view_component.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "simplecov-console", "~> 0.9.1"
spec.add_development_dependency "slim", "~> 5.1"
spec.add_development_dependency "sprockets-rails", "~> 3.4.2"
spec.add_development_dependency "yard", "~> 0.9.25"
spec.add_development_dependency "yard", "~> 0.9.34"
spec.add_development_dependency "yard-activesupport-concern", "~> 0.0.1"
end

0 comments on commit f5a9a9c

Please sign in to comment.