rspec-rails 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +57 -0
- data/Manifest.txt +158 -0
- data/README.txt +81 -0
- data/Rakefile +39 -0
- data/UPGRADE +7 -0
- data/generators/rspec/CHANGES +1 -0
- data/generators/rspec/rspec_generator.rb +40 -0
- data/generators/rspec/templates/all_stories.rb +4 -0
- data/generators/rspec/templates/previous_failures.txt +0 -0
- data/generators/rspec/templates/rcov.opts +2 -0
- data/generators/rspec/templates/rspec.rake +132 -0
- data/generators/rspec/templates/script/autospec +3 -0
- data/generators/rspec/templates/script/spec +4 -0
- data/generators/rspec/templates/script/spec_server +116 -0
- data/generators/rspec/templates/spec.opts +4 -0
- data/generators/rspec/templates/spec_helper.rb +47 -0
- data/generators/rspec/templates/stories_helper.rb +3 -0
- data/generators/rspec_controller/USAGE +33 -0
- data/generators/rspec_controller/rspec_controller_generator.rb +49 -0
- data/generators/rspec_controller/templates/controller_spec.rb +25 -0
- data/generators/rspec_controller/templates/helper_spec.rb +11 -0
- data/generators/rspec_controller/templates/view_spec.rb +12 -0
- data/generators/rspec_default_values.rb +19 -0
- data/generators/rspec_model/USAGE +18 -0
- data/generators/rspec_model/rspec_model_generator.rb +35 -0
- data/generators/rspec_model/templates/model_spec.rb +15 -0
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
- data/generators/rspec_scaffold/templates/controller_spec.rb +173 -0
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +26 -0
- data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +26 -0
- data/generators/rspec_scaffold/templates/routing_spec.rb +59 -0
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
- data/init.rb +9 -0
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rails_rspec.rb +76 -0
- data/lib/spec/rails.rb +15 -0
- data/lib/spec/rails/example.rb +47 -0
- data/lib/spec/rails/example/assigns_hash_proxy.rb +43 -0
- data/lib/spec/rails/example/controller_example_group.rb +256 -0
- data/lib/spec/rails/example/cookies_proxy.rb +25 -0
- data/lib/spec/rails/example/functional_example_group.rb +87 -0
- data/lib/spec/rails/example/helper_example_group.rb +166 -0
- data/lib/spec/rails/example/model_example_group.rb +14 -0
- data/lib/spec/rails/example/rails_example_group.rb +33 -0
- data/lib/spec/rails/example/render_observer.rb +93 -0
- data/lib/spec/rails/example/view_example_group.rb +183 -0
- data/lib/spec/rails/extensions.rb +12 -0
- data/lib/spec/rails/extensions/action_controller/base.rb +14 -0
- data/lib/spec/rails/extensions/action_controller/rescue.rb +21 -0
- data/lib/spec/rails/extensions/action_controller/test_response.rb +11 -0
- data/lib/spec/rails/extensions/action_view/base.rb +31 -0
- data/lib/spec/rails/extensions/active_record/base.rb +30 -0
- data/lib/spec/rails/extensions/object.rb +5 -0
- data/lib/spec/rails/extensions/spec/example/configuration.rb +71 -0
- data/lib/spec/rails/extensions/spec/matchers/have.rb +21 -0
- data/lib/spec/rails/interop/testcase.rb +14 -0
- data/lib/spec/rails/matchers.rb +31 -0
- data/lib/spec/rails/matchers/assert_select.rb +131 -0
- data/lib/spec/rails/matchers/change.rb +11 -0
- data/lib/spec/rails/matchers/have_text.rb +57 -0
- data/lib/spec/rails/matchers/include_text.rb +54 -0
- data/lib/spec/rails/matchers/redirect_to.rb +113 -0
- data/lib/spec/rails/matchers/render_template.rb +90 -0
- data/lib/spec/rails/mocks.rb +132 -0
- data/lib/spec/rails/story_adapter.rb +79 -0
- data/lib/spec/rails/version.rb +15 -0
- data/spec/rails/autotest/mappings_spec.rb +36 -0
- data/spec/rails/example/assigns_hash_proxy_spec.rb +65 -0
- data/spec/rails/example/configuration_spec.rb +83 -0
- data/spec/rails/example/controller_isolation_spec.rb +62 -0
- data/spec/rails/example/controller_spec_spec.rb +272 -0
- data/spec/rails/example/cookies_proxy_spec.rb +74 -0
- data/spec/rails/example/example_group_factory_spec.rb +112 -0
- data/spec/rails/example/helper_spec_spec.rb +161 -0
- data/spec/rails/example/model_spec_spec.rb +18 -0
- data/spec/rails/example/shared_behaviour_spec.rb +16 -0
- data/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
- data/spec/rails/example/view_spec_spec.rb +280 -0
- data/spec/rails/extensions/action_controller_rescue_action_spec.rb +54 -0
- data/spec/rails/extensions/action_view_base_spec.rb +48 -0
- data/spec/rails/extensions/active_record_spec.rb +14 -0
- data/spec/rails/interop/testcase_spec.rb +66 -0
- data/spec/rails/matchers/assert_select_spec.rb +814 -0
- data/spec/rails/matchers/description_generation_spec.rb +37 -0
- data/spec/rails/matchers/errors_on_spec.rb +13 -0
- data/spec/rails/matchers/have_text_spec.rb +62 -0
- data/spec/rails/matchers/include_text_spec.rb +64 -0
- data/spec/rails/matchers/redirect_to_spec.rb +209 -0
- data/spec/rails/matchers/render_template_spec.rb +176 -0
- data/spec/rails/matchers/should_change_spec.rb +15 -0
- data/spec/rails/mocks/ar_classes.rb +10 -0
- data/spec/rails/mocks/mock_model_spec.rb +106 -0
- data/spec/rails/mocks/stub_model_spec.rb +80 -0
- data/spec/rails/sample_modified_fixture.rb +8 -0
- data/spec/rails/sample_spec.rb +8 -0
- data/spec/rails/spec_server_spec.rb +96 -0
- data/spec/rails/spec_spec.rb +11 -0
- data/spec/rails_suite.rb +7 -0
- data/spec/spec_helper.rb +57 -0
- data/spec_resources/controllers/action_view_base_spec_controller.rb +2 -0
- data/spec_resources/controllers/controller_spec_controller.rb +94 -0
- data/spec_resources/controllers/redirect_spec_controller.rb +59 -0
- data/spec_resources/controllers/render_spec_controller.rb +30 -0
- data/spec_resources/controllers/rjs_spec_controller.rb +58 -0
- data/spec_resources/helpers/explicit_helper.rb +38 -0
- data/spec_resources/helpers/more_explicit_helper.rb +5 -0
- data/spec_resources/helpers/plugin_application_helper.rb +6 -0
- data/spec_resources/helpers/view_spec_helper.rb +13 -0
- data/spec_resources/views/controller_spec/_partial.rhtml +0 -0
- data/spec_resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml +1 -0
- data/spec_resources/views/controller_spec/action_setting_flash_before_session_reset.rhtml +1 -0
- data/spec_resources/views/controller_spec/action_setting_the_assigns_hash.rhtml +0 -0
- data/spec_resources/views/controller_spec/action_with_errors_in_template.rhtml +1 -0
- data/spec_resources/views/controller_spec/action_with_template.rhtml +1 -0
- data/spec_resources/views/layouts/application.rhtml +0 -0
- data/spec_resources/views/layouts/simple.rhtml +0 -0
- data/spec_resources/views/objects/_object.html.erb +1 -0
- data/spec_resources/views/render_spec/_a_partial.rhtml +0 -0
- data/spec_resources/views/render_spec/action_with_alternate_layout.rhtml +0 -0
- data/spec_resources/views/render_spec/some_action.js.rjs +1 -0
- data/spec_resources/views/render_spec/some_action.rhtml +0 -0
- data/spec_resources/views/render_spec/some_action.rjs +1 -0
- data/spec_resources/views/rjs_spec/_replacement_partial.rhtml +1 -0
- data/spec_resources/views/rjs_spec/hide_div.rjs +1 -0
- data/spec_resources/views/rjs_spec/hide_page_element.rjs +1 -0
- data/spec_resources/views/rjs_spec/insert_html.rjs +1 -0
- data/spec_resources/views/rjs_spec/replace.rjs +1 -0
- data/spec_resources/views/rjs_spec/replace_html.rjs +1 -0
- data/spec_resources/views/rjs_spec/replace_html_with_partial.rjs +1 -0
- data/spec_resources/views/rjs_spec/visual_effect.rjs +1 -0
- data/spec_resources/views/rjs_spec/visual_toggle_effect.rjs +1 -0
- data/spec_resources/views/tag_spec/no_tags.rhtml +1 -0
- data/spec_resources/views/tag_spec/single_div_with_no_attributes.rhtml +1 -0
- data/spec_resources/views/tag_spec/single_div_with_one_attribute.rhtml +1 -0
- data/spec_resources/views/view_spec/_partial.rhtml +2 -0
- data/spec_resources/views/view_spec/_partial_used_twice.rhtml +0 -0
- data/spec_resources/views/view_spec/_partial_with_local_variable.rhtml +1 -0
- data/spec_resources/views/view_spec/_partial_with_sub_partial.rhtml +1 -0
- data/spec_resources/views/view_spec/_spacer.rhtml +1 -0
- data/spec_resources/views/view_spec/accessor.rhtml +5 -0
- data/spec_resources/views/view_spec/block_helper.rhtml +3 -0
- data/spec_resources/views/view_spec/entry_form.rhtml +2 -0
- data/spec_resources/views/view_spec/explicit_helper.rhtml +2 -0
- data/spec_resources/views/view_spec/foo/show.rhtml +1 -0
- data/spec_resources/views/view_spec/implicit_helper.rhtml +2 -0
- data/spec_resources/views/view_spec/multiple_helpers.rhtml +3 -0
- data/spec_resources/views/view_spec/should_not_receive.rhtml +3 -0
- data/spec_resources/views/view_spec/template_with_partial.rhtml +5 -0
- data/spec_resources/views/view_spec/template_with_partial_using_collection.rhtml +3 -0
- data/spec_resources/views/view_spec/template_with_partial_with_array.rhtml +1 -0
- data/stories/all.rb +10 -0
- data/stories/configuration/stories.rb +5 -0
- data/stories/helper.rb +6 -0
- data/stories/steps/people.rb +8 -0
- data/stories/transactions_should_rollback +15 -0
- data/stories/transactions_should_rollback.rb +25 -0
- metadata +234 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec'
|
2
|
+
|
3
|
+
require 'spec/rails/extensions/object'
|
4
|
+
|
5
|
+
require 'spec/rails/extensions/spec/example/configuration'
|
6
|
+
require 'spec/rails/extensions/spec/matchers/have'
|
7
|
+
|
8
|
+
require 'spec/rails/extensions/active_record/base'
|
9
|
+
require 'spec/rails/extensions/action_controller/base'
|
10
|
+
require 'spec/rails/extensions/action_controller/rescue'
|
11
|
+
require 'spec/rails/extensions/action_controller/test_response'
|
12
|
+
require 'spec/rails/extensions/action_view/base'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActionController
|
2
|
+
module Rescue
|
3
|
+
def use_rails_error_handling!
|
4
|
+
@use_rails_error_handling = true
|
5
|
+
end
|
6
|
+
|
7
|
+
def use_rails_error_handling?
|
8
|
+
@use_rails_error_handling ||= false
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def rescue_action_with_fast_errors(exception)
|
13
|
+
if use_rails_error_handling?
|
14
|
+
rescue_action_without_fast_errors exception
|
15
|
+
else
|
16
|
+
raise exception
|
17
|
+
end
|
18
|
+
end
|
19
|
+
alias_method_chain :rescue_action, :fast_errors
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActionView #:nodoc:
|
2
|
+
class Base #:nodoc:
|
3
|
+
include Spec::Rails::Example::RenderObserver
|
4
|
+
cattr_accessor :base_view_path
|
5
|
+
def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc:
|
6
|
+
if partial_path.is_a?(String)
|
7
|
+
unless partial_path.include?("/")
|
8
|
+
unless self.class.base_view_path.nil?
|
9
|
+
partial_path = "#{self.class.base_view_path}/#{partial_path}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
super(partial_path, local_assigns, deprecated_local_assigns)
|
15
|
+
rescue ArgumentError # edge rails > 2.1 changed render_partial to accept only one arg
|
16
|
+
super(partial_path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :orig_render, :render
|
21
|
+
def render(options = {}, old_local_assigns = {}, &block)
|
22
|
+
if render_proxy.send(:__mock_proxy).send(:find_matching_expectation, :render, options)
|
23
|
+
render_proxy.render(options)
|
24
|
+
else
|
25
|
+
unless render_proxy.send(:__mock_proxy).send(:find_matching_method_stub, :render, options)
|
26
|
+
orig_render(options, old_local_assigns, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
if defined?(ActiveRecord::Base)
|
2
|
+
module ActiveRecord #:nodoc:
|
3
|
+
class Base
|
4
|
+
|
5
|
+
(class << self; self; end).class_eval do
|
6
|
+
# Extension for <tt>should have</tt> on AR Model classes
|
7
|
+
#
|
8
|
+
# ModelClass.should have(:no).records
|
9
|
+
# ModelClass.should have(1).record
|
10
|
+
# ModelClass.should have(n).records
|
11
|
+
def records
|
12
|
+
find(:all)
|
13
|
+
end
|
14
|
+
alias :record :records
|
15
|
+
end
|
16
|
+
|
17
|
+
# Extension for <tt>should have</tt> on AR Model instances
|
18
|
+
#
|
19
|
+
# model.should have(:no).errors_on(:attribute)
|
20
|
+
# model.should have(1).error_on(:attribute)
|
21
|
+
# model.should have(n).errors_on(:attribute)
|
22
|
+
def errors_on(attribute)
|
23
|
+
self.valid?
|
24
|
+
[self.errors.on(attribute)].flatten.compact
|
25
|
+
end
|
26
|
+
alias :error_on :errors_on
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec/example/configuration'
|
2
|
+
begin
|
3
|
+
module Spec
|
4
|
+
module Example
|
5
|
+
class Configuration
|
6
|
+
# Rails 1.2.3 does a copy of the @inheritable_attributes to the subclass when the subclass is
|
7
|
+
# created. This causes an ordering issue when setting state on Configuration because the data is
|
8
|
+
# already copied.
|
9
|
+
# Iterating over EXAMPLE_GROUP_CLASSES causes the base ExampleGroup classes to have their
|
10
|
+
# @inheritable_attributes updated.
|
11
|
+
# TODO: BT - When we no longer support Rails 1.2.3, we can remove this functionality
|
12
|
+
EXAMPLE_GROUP_CLASSES = [
|
13
|
+
::Test::Unit::TestCase,
|
14
|
+
::Spec::Rails::Example::RailsExampleGroup,
|
15
|
+
::Spec::Rails::Example::FunctionalExampleGroup,
|
16
|
+
::Spec::Rails::Example::ControllerExampleGroup,
|
17
|
+
::Spec::Rails::Example::ViewExampleGroup,
|
18
|
+
::Spec::Rails::Example::HelperExampleGroup,
|
19
|
+
::Spec::Rails::Example::ModelExampleGroup
|
20
|
+
]
|
21
|
+
# All of this is ActiveRecord related and makes no sense if it's not used by the app
|
22
|
+
if defined?(ActiveRecord::Base)
|
23
|
+
def initialize
|
24
|
+
super
|
25
|
+
self.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
26
|
+
end
|
27
|
+
|
28
|
+
def use_transactional_fixtures
|
29
|
+
Test::Unit::TestCase.use_transactional_fixtures
|
30
|
+
end
|
31
|
+
def use_transactional_fixtures=(value)
|
32
|
+
EXAMPLE_GROUP_CLASSES.each do |example_group|
|
33
|
+
example_group.use_transactional_fixtures = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def use_instantiated_fixtures
|
38
|
+
Test::Unit::TestCase.use_instantiated_fixtures
|
39
|
+
end
|
40
|
+
def use_instantiated_fixtures=(value)
|
41
|
+
EXAMPLE_GROUP_CLASSES.each do |example_group|
|
42
|
+
example_group.use_instantiated_fixtures = value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def fixture_path
|
47
|
+
Test::Unit::TestCase.fixture_path
|
48
|
+
end
|
49
|
+
def fixture_path=(path)
|
50
|
+
EXAMPLE_GROUP_CLASSES.each do |example_group|
|
51
|
+
example_group.fixture_path = path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def global_fixtures
|
56
|
+
::Test::Unit::TestCase.fixture_table_names
|
57
|
+
end
|
58
|
+
def global_fixtures=(fixtures)
|
59
|
+
EXAMPLE_GROUP_CLASSES.each do |example_group|
|
60
|
+
example_group.fixtures(*fixtures)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
rescue Exception => e
|
68
|
+
puts e.message
|
69
|
+
puts e.backtrace
|
70
|
+
raise e
|
71
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec/matchers/have'
|
2
|
+
|
3
|
+
module Spec #:nodoc:
|
4
|
+
module Matchers #:nodoc:
|
5
|
+
class Have #:nodoc:
|
6
|
+
alias_method :__original_failure_message, :failure_message
|
7
|
+
def failure_message
|
8
|
+
return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
|
9
|
+
return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
|
10
|
+
return __original_failure_message
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method :__original_description, :description
|
14
|
+
def description
|
15
|
+
return "should have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
|
16
|
+
return "should have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
|
17
|
+
return __original_description
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Test
|
2
|
+
module Unit
|
3
|
+
class TestCase
|
4
|
+
# Edge rails (r8664) introduces class-wide setup & teardown callbacks for Test::Unit::TestCase.
|
5
|
+
# Make sure these still get run when running TestCases under rspec:
|
6
|
+
prepend_before(:each) do
|
7
|
+
run_callbacks :setup if respond_to?(:run_callbacks)
|
8
|
+
end
|
9
|
+
append_after(:each) do
|
10
|
+
run_callbacks :teardown if respond_to?(:run_callbacks)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require 'spec/rails/matchers/assert_select'
|
3
|
+
require 'spec/rails/matchers/change'
|
4
|
+
require 'spec/rails/matchers/have_text'
|
5
|
+
require 'spec/rails/matchers/include_text'
|
6
|
+
require 'spec/rails/matchers/redirect_to'
|
7
|
+
require 'spec/rails/matchers/render_template'
|
8
|
+
|
9
|
+
module Spec
|
10
|
+
module Rails
|
11
|
+
# Spec::Rails::Expectations::Matchers provides several expectation matchers
|
12
|
+
# intended to work with Rails components like models and responses. For example:
|
13
|
+
#
|
14
|
+
# response.should redirect_to("some/url") #redirect_to(url) is the matcher.
|
15
|
+
#
|
16
|
+
# In addition to those you see below, the arbitrary predicate feature of RSpec
|
17
|
+
# makes the following available as well:
|
18
|
+
#
|
19
|
+
# response.should be_success #passes if response.success?
|
20
|
+
# response.should be_redirect #passes if response.redirect?
|
21
|
+
#
|
22
|
+
# Note that many of these matchers are part of a wrapper of <tt>assert_select</tt>, so
|
23
|
+
# the documentation comes straight from that with some slight modifications.
|
24
|
+
# <tt>assert_select</tt> is a Test::Unit extension originally contributed to the
|
25
|
+
# Rails community as a plugin by Assaf Arkin and eventually shipped as part of Rails.
|
26
|
+
#
|
27
|
+
# For more info on <tt>assert_select</tt>, see the relevant Rails documentation.
|
28
|
+
module Matchers
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# This is a wrapper of assert_select for rspec.
|
2
|
+
|
3
|
+
module Spec # :nodoc:
|
4
|
+
module Rails
|
5
|
+
module Matchers
|
6
|
+
|
7
|
+
class AssertSelect #:nodoc:
|
8
|
+
|
9
|
+
def initialize(assertion, spec_scope, *args, &block)
|
10
|
+
@assertion = assertion
|
11
|
+
@spec_scope = spec_scope
|
12
|
+
@args = args
|
13
|
+
@block = block
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches?(response_or_text, &block)
|
17
|
+
if ActionController::TestResponse === response_or_text and
|
18
|
+
response_or_text.headers.key?('Content-Type') and
|
19
|
+
!response_or_text.headers['Content-Type'].blank? and
|
20
|
+
response_or_text.headers['Content-Type'].to_sym == :xml
|
21
|
+
@args.unshift(HTML::Document.new(response_or_text.body, false, true).root)
|
22
|
+
elsif String === response_or_text
|
23
|
+
@args.unshift(HTML::Document.new(response_or_text).root)
|
24
|
+
end
|
25
|
+
@block = block if block
|
26
|
+
begin
|
27
|
+
@spec_scope.send(@assertion, *@args, &@block)
|
28
|
+
rescue ::Test::Unit::AssertionFailedError => @error
|
29
|
+
end
|
30
|
+
|
31
|
+
@error.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def failure_message; @error.message; end
|
35
|
+
def negative_failure_message; "should not #{description}, but did"; end
|
36
|
+
|
37
|
+
def description
|
38
|
+
{
|
39
|
+
:assert_select => "have tag#{format_args(*@args)}",
|
40
|
+
:assert_select_email => "send email#{format_args(*@args)}",
|
41
|
+
}[@assertion]
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def format_args(*args)
|
47
|
+
return "" if args.empty?
|
48
|
+
return "(#{arg_list(*args)})"
|
49
|
+
end
|
50
|
+
|
51
|
+
def arg_list(*args)
|
52
|
+
args.collect do |arg|
|
53
|
+
arg.respond_to?(:description) ? arg.description : arg.inspect
|
54
|
+
end.join(", ")
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# :call-seq:
|
60
|
+
# response.should have_tag(*args, &block)
|
61
|
+
# string.should have_tag(*args, &block)
|
62
|
+
#
|
63
|
+
# wrapper for assert_select with additional support for using
|
64
|
+
# css selectors to set expectation on Strings. Use this in
|
65
|
+
# helper specs, for example, to set expectations on the results
|
66
|
+
# of helper methods.
|
67
|
+
#
|
68
|
+
# == Examples
|
69
|
+
#
|
70
|
+
# # in a controller spec
|
71
|
+
# response.should have_tag("div", "some text")
|
72
|
+
#
|
73
|
+
# # in a helper spec (person_address_tag is a method in the helper)
|
74
|
+
# person_address_tag.should have_tag("input#person_address")
|
75
|
+
#
|
76
|
+
# see documentation for assert_select at http://api.rubyonrails.org/
|
77
|
+
def have_tag(*args, &block)
|
78
|
+
AssertSelect.new(:assert_select, self, *args, &block)
|
79
|
+
end
|
80
|
+
|
81
|
+
# wrapper for a nested assert_select
|
82
|
+
#
|
83
|
+
# response.should have_tag("div#form") do
|
84
|
+
# with_tag("input#person_name[name=?]", "person[name]")
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# see documentation for assert_select at http://api.rubyonrails.org/
|
88
|
+
def with_tag(*args, &block)
|
89
|
+
should have_tag(*args, &block)
|
90
|
+
end
|
91
|
+
|
92
|
+
# wrapper for a nested assert_select with false
|
93
|
+
#
|
94
|
+
# response.should have_tag("div#1") do
|
95
|
+
# without_tag("span", "some text that shouldn't be there")
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# see documentation for assert_select at http://api.rubyonrails.org/
|
99
|
+
def without_tag(*args, &block)
|
100
|
+
should_not have_tag(*args, &block)
|
101
|
+
end
|
102
|
+
|
103
|
+
# :call-seq:
|
104
|
+
# response.should have_rjs(*args, &block)
|
105
|
+
#
|
106
|
+
# wrapper for assert_select_rjs
|
107
|
+
#
|
108
|
+
# see documentation for assert_select_rjs at http://api.rubyonrails.org/
|
109
|
+
def have_rjs(*args, &block)
|
110
|
+
AssertSelect.new(:assert_select_rjs, self, *args, &block)
|
111
|
+
end
|
112
|
+
|
113
|
+
# :call-seq:
|
114
|
+
# response.should send_email(*args, &block)
|
115
|
+
#
|
116
|
+
# wrapper for assert_select_email
|
117
|
+
#
|
118
|
+
# see documentation for assert_select_email at http://api.rubyonrails.org/
|
119
|
+
def send_email(*args, &block)
|
120
|
+
AssertSelect.new(:assert_select_email, self, *args, &block)
|
121
|
+
end
|
122
|
+
|
123
|
+
# wrapper for assert_select_encoded
|
124
|
+
#
|
125
|
+
# see documentation for assert_select_encoded at http://api.rubyonrails.org/
|
126
|
+
def with_encoded(*args, &block)
|
127
|
+
should AssertSelect.new(:assert_select_encoded, self, *args, &block)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
class Change
|
4
|
+
def evaluate_value_proc_with_ensured_evaluation_of_proxy
|
5
|
+
value = evaluate_value_proc_without_ensured_evaluation_of_proxy
|
6
|
+
ActiveRecord::Associations::AssociationProxy === value ? value.dup : value
|
7
|
+
end
|
8
|
+
alias_method_chain :evaluate_value_proc, :ensured_evaluation_of_proxy
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Spec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
class HaveText #:nodoc:
|
6
|
+
|
7
|
+
def initialize(expected)
|
8
|
+
@expected = expected
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(response_or_text)
|
12
|
+
@actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
|
13
|
+
return actual =~ expected if Regexp === expected
|
14
|
+
return actual == expected unless Regexp === expected
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
"expected #{expected.inspect}, got #{actual.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def negative_failure_message
|
22
|
+
"expected not to have text #{expected.inspect}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"have text #{expected.inspect}"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
attr_reader :expected
|
31
|
+
attr_reader :actual
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# :call-seq:
|
36
|
+
# response.should have_text(expected)
|
37
|
+
# response.should_not have_text(expected)
|
38
|
+
#
|
39
|
+
# Accepts a String or a Regexp, matching a String using ==
|
40
|
+
# and a Regexp using =~.
|
41
|
+
#
|
42
|
+
# If response_or_text has a #body, then that is used as to match against
|
43
|
+
# else it uses response_or_text
|
44
|
+
#
|
45
|
+
# Use this instead of <tt>response.should have_tag()</tt>
|
46
|
+
# when you want to match the whole string or whole body
|
47
|
+
#
|
48
|
+
# == Examples
|
49
|
+
#
|
50
|
+
# response.should have_text("This is the expected text")
|
51
|
+
def have_text(text)
|
52
|
+
HaveText.new(text)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|