Skip to content

Commit

Permalink
more rdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 22, 2011
1 parent efcafc7 commit 620b7f3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
30 changes: 23 additions & 7 deletions lib/rspec/rails/adapters.rb
Expand Up @@ -7,16 +7,25 @@ module SetupAndTeardownAdapter
extend ActiveSupport::Concern

module ClassMethods
# @api private
#
# Wraps `setup` calls from within Rails' testing framework in `before`
# hooks.
def setup(*methods)
methods.each {|method| before { send method } }
end

# @api private
#
# Wraps `teardown` calls from within Rails' testing framework in
# `after` hooks.
def teardown(*methods)
methods.each {|method| after { send method } }
end
end

module InstanceMethods
# @api private
def method_name
@example
end
Expand All @@ -26,30 +35,37 @@ def method_name
module TestUnitAssertionAdapter
extend ActiveSupport::Concern

class AssertionDelegate
include Test::Unit::Assertions
end

module ClassMethods
# @api private
#
# Returns the names of assertion methods that we want to expose to
# examples without exposing non-assertion methods in Test::Unit or
# Minitest.
def assertion_method_names
Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/} +
[:build_message]
end

# @api private
def define_assertion_delegators
assertion_method_names.each do |m|
class_eval <<-CODE
def #{m}(*args, &block)
assertion_delegate.send :#{m}, *args, &block
assertion_delegator.send :#{m}, *args, &block
end
CODE
end
end
end

module InstanceMethods
def assertion_delegate
@assertion_delegate ||= AssertionDelegate.new
class AssertionDelegator
include Test::Unit::Assertions
end

# @api private
def assertion_delegator
@assertion_delegator ||= AssertionDelegator.new
end
end

Expand Down
32 changes: 16 additions & 16 deletions lib/rspec/rails/mocks.rb
Expand Up @@ -9,7 +9,7 @@ class IllegalDataAccessException < StandardError; end
module Mocks

module ActiveModelInstanceMethods
# Stubs +persisted?+ to return false and +id+ to return nil
# Stubs `persisted?` to return false and `id` to return nil
# @return self
def as_new_record
self.stub(:persisted?) { false }
Expand All @@ -30,7 +30,7 @@ def respond_to?(message, include_private=false)
end

module ActiveRecordInstanceMethods
# Stubs +persisted?+ to return +false+ and +id+ to return +nil+.
# Stubs `persisted?` to return `false` and `id` to return `nil`.
def destroy
self.stub(:persisted?) { false }
self.stub(:id) { nil }
Expand All @@ -41,15 +41,15 @@ def [](key)
send(key)
end

# Returns the opposite of +persisted?+
# Returns the opposite of `persisted?`
def new_record?
!persisted?
end
end

# Creates a test double representing +string_or_model_class+ with common
# Creates a test double representing `string_or_model_class` with common
# ActiveModel methods stubbed out. Additional methods may be easily
# stubbed (via add_stubs) if +stubs+ is passed. This is most useful for
# stubbed (via add_stubs) if `stubs` is passed. This is most useful for
# impersonating models that don't exist yet.
#
# NOTE that only ActiveModel's methods, plus <tt>new_record?</tt>, are
Expand All @@ -59,7 +59,7 @@ def new_record?
# ActiveModel API (which declares <tt>persisted?</tt>, not
# <tt>new_record?</tt>).
#
# +string_or_model_class+ can be any of:
# `string_or_model_class` can be any of:
#
# * A String representing a Class that does not exist
# * A String representing a Class that extends ActiveModel::Naming
Expand Down Expand Up @@ -137,27 +137,27 @@ def @object.to_s
end

module ActiveModelStubExtensions
# Stubs +persisted+ to return false and +id+ to return nil
# Stubs `persisted` to return false and `id` to return nil
def as_new_record
self.stub(:persisted?) { false }
self.stub(:id) { nil }
self
end

# Returns +true+ by default. Override with a stub.
# Returns `true` by default. Override with a stub.
def persisted?
true
end
end

module ActiveRecordStubExtensions
# Stubs +id+ (or other primary key method) to return nil
# Stubs `id` (or other primary key method) to return nil
def as_new_record
self.__send__("#{self.class.primary_key}=", nil)
super
end

# Returns the opposite of +persisted?+.
# Returns the opposite of `persisted?`.
def new_record?
!persisted?
end
Expand All @@ -169,21 +169,21 @@ def connection
end
end

# Creates an instance of +Model+ with +to_param+ stubbed using a
# generated value that is unique to each object.. If +Model+ is an
# +ActiveRecord+ model, it is prohibited from accessing the database*.
# Creates an instance of `Model` with `to_param` stubbed using a
# generated value that is unique to each object.. If `Model` is an
# `ActiveRecord` model, it is prohibited from accessing the database*.
#
# For each key in +hash_of_stubs+, if the model has a matching attribute
# For each key in `hash_of_stubs`, if the model has a matching attribute
# (determined by asking it) are simply assigned the submitted values. If
# the model does not have a matching attribute, the key/value pair is
# assigned as a stub return value using RSpec's mocking/stubbing
# framework.
#
# <tt>persisted?</tt> is overridden to return the result of !id.nil?
# This means that by default persisted? will return true. If you want
# the object to behave as a new record, sending it +as_new_record+ will
# the object to behave as a new record, sending it `as_new_record` will
# set the id to nil. You can also explicitly set :id => nil, in which
# case persisted? will return false, but using +as_new_record+ makes the
# case persisted? will return false, but using `as_new_record` makes the
# example a bit more descriptive.
#
# While you can use stub_model in any example (model, view, controller,
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/rails/view_assigns.rb
Expand Up @@ -32,6 +32,7 @@ def view_assigns
end
end

# @api private
def _assigns
super.merge(_encapsulated_assigns)
end
Expand Down
10 changes: 8 additions & 2 deletions lib/rspec/rails/view_rendering.rb
Expand Up @@ -34,22 +34,25 @@ def metadata_for_rspec_rails
metadata[:rspec_rails] = metadata[:rspec_rails] ? metadata[:rspec_rails].dup : {}
end

# See RSpec::Rails::ControllerExampleGroup
# @see RSpec::Rails::ControllerExampleGroup
def render_views(true_or_false=true)
metadata_for_rspec_rails[:render_views] = true_or_false
end

# @deprecated use render_views
def integrate_views
RSpec.deprecate("integrate_views","render_views")
render_views
end

# @api private
def render_views?
metadata_for_rspec_rails[:render_views] || RSpec.configuration.render_views?
end
end

module InstanceMethods
# @api private
def render_views?
self.class.render_views? || !controller.class.respond_to?(:view_paths)
end
Expand All @@ -64,6 +67,7 @@ def initialize(original_path_set)
@original_path_set = original_path_set
end

# @api private
def find_all(*args)
original_path_set.find_all(*args).collect do |template|
::ActionView::Template.new(
Expand All @@ -80,15 +84,18 @@ def find_all(*args)
end

module EmptyTemplates
# @api private
def prepend_view_path(new_path)
lookup_context.view_paths.unshift(*_path_decorator(new_path))
end

# @api private
def append_view_path(new_path)
lookup_context.view_paths.push(*_path_decorator(new_path))
end

private

def _path_decorator(path)
EmptyTemplatePathSetDecorator.new(::ActionView::Base::process_view_paths(path))
end
Expand All @@ -109,7 +116,6 @@ def _path_decorator(path)
end
end
end

end
end
end

0 comments on commit 620b7f3

Please sign in to comment.