Skip to content

Address yard issues #1379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
--no-private
--exclude features
--exclude lib/generators/([^/]+/)*.*_spec.rb
--exclude lib/generators/([^/]+/)*templates/([^/]+/)*.rb
--exclude lib/generators/([^/]+/)*templates/.+\.rb
--markup markdown
--template-path yard/template/
-
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ gemspec
rspec_dependencies_gemfile = File.expand_path("../Gemfile-rspec-dependencies", __FILE__)
eval_gemfile rspec_dependencies_gemfile

gem 'yard', '~> 0.8.7', :require => false

### deps for rdoc.info
group :documentation do
gem 'yard', '0.8.7.3', :require => false
gem 'redcarpet', '2.3.0'
gem 'github-markup', '1.0.0'
end
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/rails/adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module RSpec
module Rails
# @private
def self.disable_testunit_autorun
# `Test::Unit::AutoRunner.need_auto_run=` was introduced to the test-unit
# gem in version 2.4.9. Previous to this version `Test::Unit.run=` was
Expand Down
30 changes: 16 additions & 14 deletions lib/rspec/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,25 @@ def self.initialize_configuration(config)
# but requires this workaround:
config.add_setting :rendering_views, :default => false

def config.render_views=(val)
self.rendering_views = val
end
config.instance_exec do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is instance_exec really necessary to fix up the yard?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YARD issues warnings about writing the methods directly on the object:

[warn]: in YARD::Handlers::Ruby::MethodHandler: Undocumentable method defined on object instance
[warn]: in file 'lib/rspec/rails/configuration.rb':73:

    73: def config.render_views=(val)

Using instance_exec provides access to the same singleton scope allowing us to write the methods. Another option would be place all of those methods into a module and then access the singleton class directly (providing proper 1.8.7 backwards compat) to include the aforementioned module.

def render_views=(val)
self.rendering_views = val
end

def config.render_views
self.rendering_views = true
end
def render_views
self.rendering_views = true
end

def config.render_views?
rendering_views
end
def render_views?
rendering_views
end

def config.infer_spec_type_from_file_location!
DIRECTORY_MAPPINGS.each do |type, dir_parts|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
define_derived_metadata(:file_path => escaped_path) do |metadata|
metadata[:type] ||= type
def infer_spec_type_from_file_location!
DIRECTORY_MAPPINGS.each do |type, dir_parts|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
define_derived_metadata(:file_path => escaped_path) do |metadata|
metadata[:type] ||= type
end
end
end
end
Expand Down
15 changes: 13 additions & 2 deletions lib/rspec/rails/example/controller_example_group.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module RSpec
module Rails
# @private
ControllerAssertionDelegator = RSpec::Rails::AssertionDelegator.new(
ActionDispatch::Assertions::RoutingAssertions
)

# Container module for controller spec functionality.
module ControllerExampleGroup
extend ActiveSupport::Concern
Expand All @@ -9,7 +14,7 @@ module ControllerExampleGroup
include RSpec::Rails::Matchers::RedirectTo
include RSpec::Rails::Matchers::RenderTemplate
include RSpec::Rails::Matchers::RoutingMatchers
include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)
include ControllerAssertionDelegator

# Class-level DSL for controller specs.
module ClassMethods
Expand Down Expand Up @@ -117,7 +122,13 @@ def routes
end
end

attr_reader :controller, :routes
# @!attribute [r]
# Returns the controller object instance under test.
attr_reader :controller

# @!attribute [r]
# Returns the Rails routes used for the spec.
attr_reader :routes

# @private
#
Expand Down
9 changes: 8 additions & 1 deletion lib/rspec/rails/example/routing_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

module RSpec
module Rails
# @private
RoutingAssertionDelegator = RSpec::Rails::AssertionDelegator.new(
ActionDispatch::Assertions::RoutingAssertions
)

# Container module for routing spec functionality.
module RoutingExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::Matchers::RoutingMatchers
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)
include RSpec::Rails::RoutingAssertionDelegator

# Class-level DSL for route specs.
module ClassMethods
Expand Down Expand Up @@ -37,6 +42,8 @@ def routes
end
end

# @!attribute [r]
# @private
attr_reader :routes

# @private
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/rails/feature_check.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @api private
module RSpec
module Rails
# @private
# Disable some cops until https://github.com/bbatsov/rubocop/issues/1310
# rubocop:disable Style/IndentationConsistency
module FeatureCheck
Expand Down
8 changes: 7 additions & 1 deletion lib/rspec/rails/view_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ module Rails
module ViewRendering
extend ActiveSupport::Concern

attr_accessor :controller
# @!attribute [r]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is just here to declare the attribute is read-only, right? Should we consider changing attr_accessor to attr_reader to actually make it read only? And/or we could do private :controller= to make the writer private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was a copy-paste mistake. But yes, I believe you are correct, we should note that controller= is a private API call. Thanks for catching it!

# Returns the controller object instance under test.
attr_reader :controller

# @private
attr_writer :controller
private :controller=

# DSL methods
module ClassMethods
Expand Down