carlosbrando-remarkable 0.0.99
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +124 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +29 -0
- data/init.rb +1 -0
- data/lib/remarkable.rb +13 -0
- data/lib/remarkable/active_record/active_record.rb +21 -0
- data/lib/remarkable/active_record/helpers.rb +16 -0
- data/lib/remarkable/active_record/macros/associations/belong_to.rb +81 -0
- data/lib/remarkable/active_record/macros/associations/have_and_belong_to_many.rb +77 -0
- data/lib/remarkable/active_record/macros/associations/have_many.rb +160 -0
- data/lib/remarkable/active_record/macros/associations/have_one.rb +133 -0
- data/lib/remarkable/active_record/macros/database/have_db_column.rb +81 -0
- data/lib/remarkable/active_record/macros/database/have_db_columns.rb +73 -0
- data/lib/remarkable/active_record/macros/database/have_indices.rb +75 -0
- data/lib/remarkable/active_record/macros/validations/allow_values_for.rb +103 -0
- data/lib/remarkable/active_record/macros/validations/ensure_length_at_least.rb +97 -0
- data/lib/remarkable/active_record/macros/validations/ensure_length_in_range.rb +134 -0
- data/lib/remarkable/active_record/macros/validations/ensure_length_is.rb +106 -0
- data/lib/remarkable/active_record/macros/validations/ensure_value_in_range.rb +117 -0
- data/lib/remarkable/active_record/macros/validations/have_class_methods.rb +74 -0
- data/lib/remarkable/active_record/macros/validations/have_instance_methods.rb +74 -0
- data/lib/remarkable/active_record/macros/validations/have_named_scope.rb +148 -0
- data/lib/remarkable/active_record/macros/validations/have_readonly_attributes.rb +81 -0
- data/lib/remarkable/active_record/macros/validations/only_allow_numeric_values_for.rb +89 -0
- data/lib/remarkable/active_record/macros/validations/protect_attributes.rb +89 -0
- data/lib/remarkable/active_record/macros/validations/require_acceptance_of.rb +94 -0
- data/lib/remarkable/active_record/macros/validations/require_attributes.rb +94 -0
- data/lib/remarkable/active_record/macros/validations/require_unique_attributes.rb +146 -0
- data/lib/remarkable/controller/controller.rb +15 -0
- data/lib/remarkable/controller/helpers.rb +48 -0
- data/lib/remarkable/controller/macros/assign_to.rb +110 -0
- data/lib/remarkable/controller/macros/filter_params.rb +52 -0
- data/lib/remarkable/controller/macros/redirect_to.rb +24 -0
- data/lib/remarkable/controller/macros/render_a_form.rb +23 -0
- data/lib/remarkable/controller/macros/render_template.rb +18 -0
- data/lib/remarkable/controller/macros/render_with_layout.rb +61 -0
- data/lib/remarkable/controller/macros/respond_with.rb +86 -0
- data/lib/remarkable/controller/macros/respond_with_content_type.rb +45 -0
- data/lib/remarkable/controller/macros/return_from_session.rb +45 -0
- data/lib/remarkable/controller/macros/route.rb +91 -0
- data/lib/remarkable/controller/macros/set_the_flash_to.rb +58 -0
- data/lib/remarkable/example/example_methods.rb +32 -0
- data/lib/remarkable/private_helpers.rb +123 -0
- data/rails/init.rb +1 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/controllers/posts_controller_spec.rb +166 -0
- data/spec/controllers/users_controller_spec.rb +14 -0
- data/spec/fixtures/addresses.yml +3 -0
- data/spec/fixtures/friendships.yml +0 -0
- data/spec/fixtures/posts.yml +5 -0
- data/spec/fixtures/products.yml +0 -0
- data/spec/fixtures/taggings.yml +0 -0
- data/spec/fixtures/tags.yml +9 -0
- data/spec/fixtures/users.yml +6 -0
- data/spec/models/address_spec.rb +21 -0
- data/spec/models/dog_spec.rb +17 -0
- data/spec/models/flea_spec.rb +9 -0
- data/spec/models/friendship_spec.rb +13 -0
- data/spec/models/post_spec.rb +35 -0
- data/spec/models/product_spec.rb +57 -0
- data/spec/models/tag_spec.rb +21 -0
- data/spec/models/tagging_spec.rb +13 -0
- data/spec/models/user_spec.rb +107 -0
- data/spec/rails_root/app/controllers/application.rb +25 -0
- data/spec/rails_root/app/controllers/posts_controller.rb +85 -0
- data/spec/rails_root/app/controllers/users_controller.rb +84 -0
- data/spec/rails_root/app/helpers/application_helper.rb +3 -0
- data/spec/rails_root/app/helpers/posts_helper.rb +2 -0
- data/spec/rails_root/app/helpers/users_helper.rb +2 -0
- data/spec/rails_root/app/models/address.rb +7 -0
- data/spec/rails_root/app/models/dog.rb +5 -0
- data/spec/rails_root/app/models/flea.rb +3 -0
- data/spec/rails_root/app/models/friendship.rb +4 -0
- data/spec/rails_root/app/models/post.rb +12 -0
- data/spec/rails_root/app/models/product.rb +12 -0
- data/spec/rails_root/app/models/tag.rb +8 -0
- data/spec/rails_root/app/models/tagging.rb +4 -0
- data/spec/rails_root/app/models/user.rb +28 -0
- data/spec/rails_root/app/views/layouts/posts.rhtml +17 -0
- data/spec/rails_root/app/views/layouts/users.rhtml +17 -0
- data/spec/rails_root/app/views/layouts/wide.html.erb +1 -0
- data/spec/rails_root/app/views/posts/edit.rhtml +27 -0
- data/spec/rails_root/app/views/posts/index.rhtml +25 -0
- data/spec/rails_root/app/views/posts/new.rhtml +26 -0
- data/spec/rails_root/app/views/posts/show.rhtml +18 -0
- data/spec/rails_root/app/views/users/edit.rhtml +22 -0
- data/spec/rails_root/app/views/users/index.rhtml +22 -0
- data/spec/rails_root/app/views/users/new.rhtml +21 -0
- data/spec/rails_root/app/views/users/show.rhtml +13 -0
- data/spec/rails_root/config/boot.rb +109 -0
- data/spec/rails_root/config/database.yml +4 -0
- data/spec/rails_root/config/environment.rb +14 -0
- data/spec/rails_root/config/environments/sqlite3.rb +0 -0
- data/spec/rails_root/config/initializers/new_rails_defaults.rb +15 -0
- data/spec/rails_root/config/initializers/shoulda.rb +8 -0
- data/spec/rails_root/config/routes.rb +6 -0
- data/spec/rails_root/db/migrate/001_create_users.rb +18 -0
- data/spec/rails_root/db/migrate/002_create_posts.rb +13 -0
- data/spec/rails_root/db/migrate/003_create_taggings.rb +12 -0
- data/spec/rails_root/db/migrate/004_create_tags.rb +11 -0
- data/spec/rails_root/db/migrate/005_create_dogs.rb +12 -0
- data/spec/rails_root/db/migrate/006_create_addresses.rb +14 -0
- data/spec/rails_root/db/migrate/007_create_fleas.rb +11 -0
- data/spec/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
- data/spec/rails_root/db/migrate/009_create_products.rb +17 -0
- data/spec/rails_root/db/migrate/010_create_friendships.rb +14 -0
- data/spec/rails_root/db/schema.rb +0 -0
- data/spec/rails_root/log/.keep +0 -0
- data/spec/rails_root/public/.htaccess +40 -0
- data/spec/rails_root/public/404.html +30 -0
- data/spec/rails_root/public/422.html +30 -0
- data/spec/rails_root/public/500.html +30 -0
- data/spec/rails_root/script/console +3 -0
- data/spec/rails_root/script/generate +3 -0
- data/spec/rails_root/vendor/plugins/.keep +0 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +58 -0
- data/tasks/rspec.rake +21 -0
- metadata +216 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
# Macro that creates a test asserting that the controller assigned to
|
6
|
+
# each of the named instance variable(s).
|
7
|
+
#
|
8
|
+
# Options:
|
9
|
+
# * <tt>:class</tt> - The expected class of the instance variable being checked.
|
10
|
+
# * <tt>:equals</tt> - A string which is evaluated and compared for equality with
|
11
|
+
# the instance variable being checked.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# it { should assign_to(:user, :posts) }
|
16
|
+
# it { should assign_to(:user, :class => User) }
|
17
|
+
# it { should assign_to(:user, :equals => '@user') }
|
18
|
+
#
|
19
|
+
def assign_to(*names)
|
20
|
+
opts = names.extract_options!
|
21
|
+
test_name = "assign @#{names.to_sentence}"
|
22
|
+
test_name << " as class #{opts[:class]}" if opts[:class]
|
23
|
+
test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
|
24
|
+
|
25
|
+
simple_matcher test_name do |controller, matcher|
|
26
|
+
ret = true
|
27
|
+
names.each do |name|
|
28
|
+
assigned_value = assigns(name.to_sym)
|
29
|
+
|
30
|
+
unless assigned_value
|
31
|
+
ret = false
|
32
|
+
break
|
33
|
+
end
|
34
|
+
|
35
|
+
if opts[:class]
|
36
|
+
unless assigned_value.kind_of?(opts[:class])
|
37
|
+
ret = false
|
38
|
+
break
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if opts[:equals]
|
43
|
+
instantiate_variables_from_assigns do
|
44
|
+
expected_value = eval(opts[:equals], self.send(:binding), __FILE__, __LINE__)
|
45
|
+
unless assigned_value == expected_value
|
46
|
+
ret = false
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ret
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module Shoulda
|
59
|
+
# Macro that creates a test asserting that the controller assigned to
|
60
|
+
# each of the named instance variable(s).
|
61
|
+
#
|
62
|
+
# Options:
|
63
|
+
# * <tt>:class</tt> - The expected class of the instance variable being checked.
|
64
|
+
# * <tt>:equals</tt> - A string which is evaluated and compared for equality with
|
65
|
+
# the instance variable being checked.
|
66
|
+
#
|
67
|
+
# Example:
|
68
|
+
#
|
69
|
+
# should_assign_to :user, :posts
|
70
|
+
# should_assign_to :user, :class => User
|
71
|
+
# should_assign_to :user, :equals => '@user'
|
72
|
+
#
|
73
|
+
def should_assign_to(*names)
|
74
|
+
opts = names.extract_options!
|
75
|
+
names.each do |name|
|
76
|
+
test_name = "should assign @#{name}"
|
77
|
+
test_name << " as class #{opts[:class]}" if opts[:class]
|
78
|
+
test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
|
79
|
+
it test_name do
|
80
|
+
assigned_value = assigns(name.to_sym)
|
81
|
+
assigned_value.should_not be_nil
|
82
|
+
assigned_value.should be_a_kind_of(opts[:class]) if opts[:class]
|
83
|
+
if opts[:equals]
|
84
|
+
instantiate_variables_from_assigns do
|
85
|
+
expected_value = eval(opts[:equals], self.send(:binding), __FILE__, __LINE__)
|
86
|
+
assigned_value.should == expected_value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Macro that creates a test asserting that the controller did not assign to
|
94
|
+
# any of the named instance variable(s).
|
95
|
+
#
|
96
|
+
# Example:
|
97
|
+
#
|
98
|
+
# should_not_assign_to :user, :posts
|
99
|
+
#
|
100
|
+
def should_not_assign_to(*names)
|
101
|
+
names.each do |name|
|
102
|
+
it "should not assign to @#{name}" do
|
103
|
+
assigns(name.to_sym).should be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
# Macro that creates a test asserting that filter_parameter_logging
|
6
|
+
# is set for the specified keys
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# should_filter_params :password, :ssn
|
11
|
+
#
|
12
|
+
def filter_params(*keys)
|
13
|
+
simple_matcher "filter #{keys.to_sentence}" do
|
14
|
+
ret = true
|
15
|
+
keys.each do |key|
|
16
|
+
if controller.respond_to?(:filter_parameters)
|
17
|
+
filtered = controller.send(:filter_parameters, {key.to_s => key.to_s})
|
18
|
+
unless filtered[key.to_s] == '[FILTERED]'
|
19
|
+
ret = false
|
20
|
+
break
|
21
|
+
end
|
22
|
+
else
|
23
|
+
ret = false
|
24
|
+
break
|
25
|
+
end
|
26
|
+
end
|
27
|
+
ret
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Shoulda
|
33
|
+
# Macro that creates a test asserting that filter_parameter_logging
|
34
|
+
# is set for the specified keys
|
35
|
+
#
|
36
|
+
# Example:
|
37
|
+
#
|
38
|
+
# should_filter_params :password, :ssn
|
39
|
+
#
|
40
|
+
def should_filter_params(*keys)
|
41
|
+
keys.each do |key|
|
42
|
+
it "should filter #{key}" do
|
43
|
+
controller.should respond_to(:filter_parameters)
|
44
|
+
filtered = controller.send(:filter_parameters, {key.to_s => key.to_s})
|
45
|
+
filtered[key.to_s].should == '[FILTERED]'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module Shoulda
|
5
|
+
# Macro that creates a test asserting that the controller returned a redirect to the given path.
|
6
|
+
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
7
|
+
# set by the controller are available to the evaled string.
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# should_redirect_to '"/"'
|
11
|
+
# should_redirect_to "user_url(@user)"
|
12
|
+
# should_redirect_to "users_url"
|
13
|
+
#
|
14
|
+
def should_redirect_to(url)
|
15
|
+
it "should redirect to #{url.inspect}" do
|
16
|
+
instantiate_variables_from_assigns do
|
17
|
+
response.should redirect_to(eval(url, self.send(:binding), __FILE__, __LINE__))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
# Macro that creates a test asserting that the rendered view contains a <form> element.
|
6
|
+
def render_a_form
|
7
|
+
simple_matcher "should display a form" do |controller|
|
8
|
+
controller.response.should have_tag("form")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Shoulda
|
14
|
+
# Macro that creates a test asserting that the rendered view contains a <form> element.
|
15
|
+
def should_render_a_form
|
16
|
+
it "should display a form" do
|
17
|
+
response.should have_tag("form")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module Shoulda
|
5
|
+
# Macro that creates a test asserting that the controller rendered the given template.
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# should_render_template :new
|
9
|
+
#
|
10
|
+
def should_render_template(template)
|
11
|
+
it "should render template #{template.inspect}" do
|
12
|
+
response.should render_template(template.to_s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
# Macro that creates a test asserting that the controller rendered with the given layout.
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# it { should render_with_layout('special') }
|
9
|
+
# it { should render_with_layout(:special) }
|
10
|
+
#
|
11
|
+
def render_with_layout(expected_layout = 'application')
|
12
|
+
if expected_layout
|
13
|
+
simple_matcher "render with #{expected_layout.inspect} layout" do |controller|
|
14
|
+
response_layout = response.layout.blank? ? "" : response.layout.split('/').last
|
15
|
+
response_layout.should == expected_layout.to_s
|
16
|
+
end
|
17
|
+
else
|
18
|
+
simple_matcher "render without layout" do
|
19
|
+
response.layout.should be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Macro that creates a test asserting that the controller rendered without a layout.
|
25
|
+
# Same as @it { should render_with_layout(false) }@
|
26
|
+
def render_without_layout
|
27
|
+
simple_matcher "render without layout" do |controller|
|
28
|
+
controller.should render_with_layout(nil)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Shoulda
|
34
|
+
# Macro that creates a test asserting that the controller rendered with the given layout.
|
35
|
+
# Example:
|
36
|
+
#
|
37
|
+
# should_render_with_layout 'special'
|
38
|
+
# should_render_with_layout :special
|
39
|
+
#
|
40
|
+
def should_render_with_layout(expected_layout = 'application')
|
41
|
+
if expected_layout
|
42
|
+
it "should render with #{expected_layout.inspect} layout" do
|
43
|
+
response_layout = response.layout.blank? ? "" : response.layout.split('/').last
|
44
|
+
response_layout.should == expected_layout.to_s
|
45
|
+
end
|
46
|
+
else
|
47
|
+
it "should render without layout" do
|
48
|
+
response.layout.should be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Macro that creates a test asserting that the controller rendered without a layout.
|
54
|
+
# Same as @should_render_with_layout false@
|
55
|
+
def should_render_without_layout
|
56
|
+
should_render_with_layout nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
class RespondWith
|
6
|
+
include Remarkable::Private
|
7
|
+
|
8
|
+
def initialize(response, type)
|
9
|
+
@response = response
|
10
|
+
@type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(controller)
|
14
|
+
@controller = controller
|
15
|
+
|
16
|
+
begin
|
17
|
+
if [ :success, :missing, :redirect, :error ].include?(@type) && @response.send("#{@type}?")
|
18
|
+
elsif @type.is_a?(Fixnum) && @response.response_code == @type
|
19
|
+
elsif @type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[@type]
|
20
|
+
else
|
21
|
+
if @response.error?
|
22
|
+
exception = @response.template.instance_variable_get(:@exception)
|
23
|
+
exception_message = exception && exception.message
|
24
|
+
fail "Expected response to be a #{@type}, but was #{@response.response_code}\n#{exception_message.to_s}"
|
25
|
+
else
|
26
|
+
fail "Expected response to be a #{@type}, but was #{@response.response_code}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
true
|
31
|
+
rescue Exception => e
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def description
|
37
|
+
"respond with #{@type}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def failure_message
|
41
|
+
@failure_message || "expected respond with #{@type}, but it didn't"
|
42
|
+
end
|
43
|
+
|
44
|
+
def negative_failure_message
|
45
|
+
"expected not respond with #{@type}, but it did"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Macro that creates a test asserting that the controller responded with a 'response' status code.
|
50
|
+
# Example:
|
51
|
+
#
|
52
|
+
# it { should respond_with(:success) }
|
53
|
+
#
|
54
|
+
def respond_with(type)
|
55
|
+
Remarkable::Syntax::RSpec::RespondWith.new(response, type)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module Shoulda
|
60
|
+
# Macro that creates a test asserting that the controller responded with a 'response' status code.
|
61
|
+
# Example:
|
62
|
+
#
|
63
|
+
# should_respond_with :success
|
64
|
+
#
|
65
|
+
def should_respond_with(type)
|
66
|
+
it "should respond with #{type}" do
|
67
|
+
clean_backtrace do
|
68
|
+
if [ :success, :missing, :redirect, :error ].include?(type) && response.send("#{type}?")
|
69
|
+
elsif type.is_a?(Fixnum) && response.response_code == type
|
70
|
+
elsif type.is_a?(Symbol) && response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
|
71
|
+
else
|
72
|
+
if response.error?
|
73
|
+
exception = response.template.instance_variable_get(:@exception)
|
74
|
+
exception_message = exception && exception.message
|
75
|
+
Spec::Expectations.fail_with "Expected response to be a #{type}, but was #{response.response_code}\n#{exception_message.to_s}"
|
76
|
+
else
|
77
|
+
Spec::Expectations.fail_with "Expected response to be a #{type}, but was #{response.response_code}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
# Macro that creates a test asserting that the response content type was 'content_type'.
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# should_respond_with_content_type 'application/rss+xml'
|
9
|
+
# should_respond_with_content_type :rss
|
10
|
+
# should_respond_with_content_type /rss/
|
11
|
+
#
|
12
|
+
def respond_with_content_type(content_type)
|
13
|
+
simple_matcher "respond with content type of #{content_type}" do
|
14
|
+
content_type = Mime::EXTENSION_LOOKUP[content_type.to_s].to_s if content_type.is_a? Symbol
|
15
|
+
if content_type.is_a? Regexp
|
16
|
+
response.content_type =~ content_type
|
17
|
+
else
|
18
|
+
response.content_type == content_type
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Shoulda
|
25
|
+
# Macro that creates a test asserting that the response content type was 'content_type'.
|
26
|
+
# Example:
|
27
|
+
#
|
28
|
+
# should_respond_with_content_type 'application/rss+xml'
|
29
|
+
# should_respond_with_content_type :rss
|
30
|
+
# should_respond_with_content_type /rss/
|
31
|
+
#
|
32
|
+
def should_respond_with_content_type(content_type)
|
33
|
+
it "should respond with content type of #{content_type}" do
|
34
|
+
content_type = Mime::EXTENSION_LOOKUP[content_type.to_s].to_s if content_type.is_a? Symbol
|
35
|
+
if content_type.is_a? Regexp
|
36
|
+
response.content_type.should match(content_type)
|
37
|
+
else
|
38
|
+
response.content_type.should == content_type
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
# Macro that creates a test asserting that a value returned from the session is correct.
|
6
|
+
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
7
|
+
# set by the controller are available to the evaled string.
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# should_return_from_session :user_id, '@user.id'
|
11
|
+
# should_return_from_session :message, '"Free stuff"'
|
12
|
+
#
|
13
|
+
def return_from_session(key, expected)
|
14
|
+
simple_matcher "return the correct value from the session for key #{key}" do
|
15
|
+
ret = true
|
16
|
+
instantiate_variables_from_assigns do
|
17
|
+
expected_value = eval(expected, self.send(:binding), __FILE__, __LINE__)
|
18
|
+
ret = (session[key] == expected_value)
|
19
|
+
end
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Shoulda
|
26
|
+
# Macro that creates a test asserting that a value returned from the session is correct.
|
27
|
+
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
28
|
+
# set by the controller are available to the evaled string.
|
29
|
+
# Example:
|
30
|
+
#
|
31
|
+
# should_return_from_session :user_id, '@user.id'
|
32
|
+
# should_return_from_session :message, '"Free stuff"'
|
33
|
+
#
|
34
|
+
def should_return_from_session(key, expected)
|
35
|
+
it "should return the correct value from the session for key #{key}" do
|
36
|
+
instantiate_variables_from_assigns do
|
37
|
+
expected_value = eval(expected, self.send(:binding), __FILE__, __LINE__)
|
38
|
+
session[key].should == expected_value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|