remarkable_rails 3.1.8 → 3.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG +91 -88
  2. data/LICENSE +20 -20
  3. data/README +80 -80
  4. data/lib/remarkable_rails/action_controller/base.rb +29 -29
  5. data/lib/remarkable_rails/action_controller/macro_stubs.rb +459 -457
  6. data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +92 -92
  7. data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +41 -41
  8. data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +119 -119
  9. data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +146 -146
  10. data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +126 -126
  11. data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +135 -109
  12. data/lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb +49 -49
  13. data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +106 -106
  14. data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +54 -54
  15. data/lib/remarkable_rails/action_controller.rb +22 -22
  16. data/lib/remarkable_rails/action_view/base.rb +7 -7
  17. data/lib/remarkable_rails/action_view.rb +18 -18
  18. data/lib/remarkable_rails/active_orm.rb +19 -19
  19. data/lib/remarkable_rails.rb +30 -30
  20. data/locale/en.yml +110 -110
  21. data/spec/action_controller/assign_to_matcher_spec.rb +142 -142
  22. data/spec/action_controller/filter_params_matcher_spec.rb +64 -64
  23. data/spec/action_controller/macro_stubs_spec.rb +234 -208
  24. data/spec/action_controller/redirect_to_matcher_spec.rb +102 -102
  25. data/spec/action_controller/render_template_matcher_spec.rb +251 -251
  26. data/spec/action_controller/respond_with_matcher_spec.rb +223 -223
  27. data/spec/action_controller/route_matcher_spec.rb +96 -79
  28. data/spec/action_controller/set_cookies_matcher_spec.rb +149 -149
  29. data/spec/action_controller/set_session_matcher_spec.rb +141 -141
  30. data/spec/action_controller/set_the_flash_matcher_spec.rb +93 -93
  31. data/spec/application/application.rb +15 -15
  32. data/spec/application/tasks_controller.rb +34 -34
  33. data/spec/functional_builder.rb +88 -88
  34. data/spec/rcov.opts +2 -2
  35. data/spec/remarkable_rails_spec.rb +5 -5
  36. data/spec/spec.opts +4 -4
  37. data/spec/spec_helper.rb +42 -42
  38. metadata +7 -7
@@ -1,149 +1,149 @@
1
- require File.join(File.dirname(__FILE__), 'respond_with_matcher')
2
-
3
- module Remarkable
4
- module ActionController
5
- module Matchers
6
- class RenderTemplateMatcher < RespondWithMatcher #:nodoc:
7
- prepend_optional :template, :layout
8
-
9
- assertions :rendered?, :template_matches?, :layout_matches?
10
-
11
- protected
12
-
13
- def rendered?
14
- return true unless @options.key?(:template)
15
-
16
- @actual = if @response.respond_to?(:rendered_file)
17
- @response.rendered_file
18
- elsif @response.respond_to?(:rendered)
19
- case template = @response.rendered[:template]
20
- when nil
21
- unless @response.rendered[:partials].empty?
22
- path_and_file(@response.rendered[:partials].keys.first).join("/_")
23
- end
24
- when ::ActionView::Template
25
- template.path
26
- when ::String
27
- template
28
- end
29
- else
30
- @response.rendered_template.to_s
31
- end
32
-
33
- !@actual.blank?
34
- end
35
-
36
- def template_matches?
37
- return true unless @options[:template] # only continue if not nil
38
-
39
- actual_controller_path, actual_file = path_and_file(@actual.to_s)
40
- expected_controller_path, expected_file = path_and_file(@options[:template].to_s)
41
-
42
- # Test if each given slice matches. Actual always return the full
43
- # file name (new.html.erb), on the other hand, the user might supply
44
- # only new. If the user supply all three pieces, we check if they
45
- # are equal, in the given order.
46
- #
47
- actual_file = actual_file.split('.')
48
- expected_file.split('.').each_with_index do |slice, i|
49
- return false unless slice == actual_file[i] || actual_file[i].nil?
50
- end
51
-
52
- actual_controller_path == expected_controller_path
53
- end
54
-
55
- def layout_matches?
56
- return true unless @options.key?(:layout)
57
- @response.layout.to_s.split('/').last.to_s == @options[:layout].to_s
58
- end
59
-
60
- def path_and_file(path)
61
- parts = path.split('/')
62
- file = parts.pop
63
- controller = parts.empty? ? @controller.controller_path : parts.join('/')
64
- return controller, file
65
- end
66
-
67
- def interpolation_options
68
- if @response
69
- super.merge!(:actual_layout => @response.layout.inspect, :actual_template => @actual.inspect)
70
- else
71
- super.merge!(:actual_template => @actual.inspect)
72
- end
73
- end
74
-
75
- end
76
-
77
- # Passes if the specified template (view file) is rendered by the
78
- # response. This file can be any view file, including a partial.
79
- #
80
- # <code>template</code> can include the controller path. It can also
81
- # include an optional extension, which you only need to use when there
82
- # is ambiguity.
83
- #
84
- # Note that partials must be spelled with the preceding underscore.
85
- #
86
- # == Options
87
- #
88
- # * <tt>:layout</tt> - The layout used when rendering the template.
89
- #
90
- # All other options in <tt>respond_with</tt> are also available.
91
- #
92
- # == Examples
93
- #
94
- # should_render_template 'list'
95
- # should_render_template 'same_controller/list'
96
- # should_render_template 'other_controller/list'
97
- #
98
- # # with extensions
99
- # should_render_template 'list.rjs'
100
- # should_render_template 'list.haml'
101
- # should_render_template 'same_controller/list.rjs'
102
- # should_render_template 'other_controller/list.rjs'
103
- #
104
- # # partials
105
- # should_render_template '_a_partial'
106
- # should_render_template 'same_controller/_a_partial'
107
- # should_render_template 'other_controller/_a_partial'
108
- #
109
- # # with options
110
- # should_render_template 'list', :layout => 'users'
111
- # should_render_template 'list', :content_type => :xml
112
- # should_render_template 'list', :content_type => /xml/
113
- # should_render_template 'list', :content_type => Mime::XML
114
- #
115
- # it { should render_template('list').layout('users') }
116
- # it { should render_template('list').content_type(:xml) }
117
- # it { should render_template('list').content_type(/xml/) }
118
- # it { should render_template('list').content_type(Mime::XML) }
119
- #
120
- # == Gotcha
121
- #
122
- # Extensions check does not work in Rails 2.1.x.
123
- #
124
- def render_template(*args, &block)
1
+ require File.join(File.dirname(__FILE__), 'respond_with_matcher')
2
+
3
+ module Remarkable
4
+ module ActionController
5
+ module Matchers
6
+ class RenderTemplateMatcher < RespondWithMatcher #:nodoc:
7
+ prepend_optional :template, :layout
8
+
9
+ assertions :rendered?, :template_matches?, :layout_matches?
10
+
11
+ protected
12
+
13
+ def rendered?
14
+ return true unless @options.key?(:template)
15
+
16
+ @actual = if @response.respond_to?(:rendered_file)
17
+ @response.rendered_file
18
+ elsif @response.respond_to?(:rendered)
19
+ case template = @response.rendered[:template]
20
+ when nil
21
+ unless @response.rendered[:partials].empty?
22
+ path_and_file(@response.rendered[:partials].keys.first).join("/_")
23
+ end
24
+ when ::ActionView::Template
25
+ template.path
26
+ when ::String
27
+ template
28
+ end
29
+ else
30
+ @response.rendered_template.to_s
31
+ end
32
+
33
+ !@actual.blank?
34
+ end
35
+
36
+ def template_matches?
37
+ return true unless @options[:template] # only continue if not nil
38
+
39
+ actual_controller_path, actual_file = path_and_file(@actual.to_s)
40
+ expected_controller_path, expected_file = path_and_file(@options[:template].to_s)
41
+
42
+ # Test if each given slice matches. Actual always return the full
43
+ # file name (new.html.erb), on the other hand, the user might supply
44
+ # only new. If the user supply all three pieces, we check if they
45
+ # are equal, in the given order.
46
+ #
47
+ actual_file = actual_file.split('.')
48
+ expected_file.split('.').each_with_index do |slice, i|
49
+ return false unless slice == actual_file[i] || actual_file[i].nil?
50
+ end
51
+
52
+ actual_controller_path == expected_controller_path
53
+ end
54
+
55
+ def layout_matches?
56
+ return true unless @options.key?(:layout)
57
+ @response.layout.to_s.split('/').last.to_s == @options[:layout].to_s
58
+ end
59
+
60
+ def path_and_file(path)
61
+ parts = path.split('/')
62
+ file = parts.pop
63
+ controller = parts.empty? ? @controller.controller_path : parts.join('/')
64
+ return controller, file
65
+ end
66
+
67
+ def interpolation_options
68
+ if @response
69
+ super.merge!(:actual_layout => @response.layout.inspect, :actual_template => @actual.inspect)
70
+ else
71
+ super.merge!(:actual_template => @actual.inspect)
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ # Passes if the specified template (view file) is rendered by the
78
+ # response. This file can be any view file, including a partial.
79
+ #
80
+ # <code>template</code> can include the controller path. It can also
81
+ # include an optional extension, which you only need to use when there
82
+ # is ambiguity.
83
+ #
84
+ # Note that partials must be spelled with the preceding underscore.
85
+ #
86
+ # == Options
87
+ #
88
+ # * <tt>:layout</tt> - The layout used when rendering the template.
89
+ #
90
+ # All other options in <tt>respond_with</tt> are also available.
91
+ #
92
+ # == Examples
93
+ #
94
+ # should_render_template 'list'
95
+ # should_render_template 'same_controller/list'
96
+ # should_render_template 'other_controller/list'
97
+ #
98
+ # # with extensions
99
+ # should_render_template 'list.rjs'
100
+ # should_render_template 'list.haml'
101
+ # should_render_template 'same_controller/list.rjs'
102
+ # should_render_template 'other_controller/list.rjs'
103
+ #
104
+ # # partials
105
+ # should_render_template '_a_partial'
106
+ # should_render_template 'same_controller/_a_partial'
107
+ # should_render_template 'other_controller/_a_partial'
108
+ #
109
+ # # with options
110
+ # should_render_template 'list', :layout => 'users'
111
+ # should_render_template 'list', :content_type => :xml
112
+ # should_render_template 'list', :content_type => /xml/
113
+ # should_render_template 'list', :content_type => Mime::XML
114
+ #
115
+ # it { should render_template('list').layout('users') }
116
+ # it { should render_template('list').content_type(:xml) }
117
+ # it { should render_template('list').content_type(/xml/) }
118
+ # it { should render_template('list').content_type(Mime::XML) }
119
+ #
120
+ # == Gotcha
121
+ #
122
+ # Extensions check does not work in Rails 2.1.x.
123
+ #
124
+ def render_template(*args, &block)
125
125
  options = args.extract_options!
126
- options.merge!(:template => args.first)
127
- RenderTemplateMatcher.new(options, &block).spec(self)
128
- end
129
-
130
- # This is just a shortcut for render_template :layout => layout. It's also
131
- # used for Shoulda compatibility. Check render_template for more information.
132
- #
133
- def render_with_layout(*args, &block)
126
+ options.merge!(:template => args.first)
127
+ RenderTemplateMatcher.new(options, &block).spec(self)
128
+ end
129
+
130
+ # This is just a shortcut for render_template :layout => layout. It's also
131
+ # used for Shoulda compatibility. Check render_template for more information.
132
+ #
133
+ def render_with_layout(*args, &block)
134
134
  options = args.extract_options!
135
- options.merge!(:layout => args.first)
136
- RenderTemplateMatcher.new(options, &block).spec(self)
137
- end
138
-
139
- # This is just a shortcut for render_template :layout => nil. It's also
140
- # used for Shoulda compatibility. Check render_template for more information.
141
- #
135
+ options.merge!(:layout => args.first)
136
+ RenderTemplateMatcher.new(options, &block).spec(self)
137
+ end
138
+
139
+ # This is just a shortcut for render_template :layout => nil. It's also
140
+ # used for Shoulda compatibility. Check render_template for more information.
141
+ #
142
142
  def render_without_layout(options={}, &block)
143
- options.merge!(:layout => nil)
144
- RenderTemplateMatcher.new(options, &block).spec(self)
145
- end
146
-
147
- end
148
- end
149
- end
143
+ options.merge!(:layout => nil)
144
+ RenderTemplateMatcher.new(options, &block).spec(self)
145
+ end
146
+
147
+ end
148
+ end
149
+ end
@@ -1,136 +1,136 @@
1
- module Remarkable
2
- module ActionController
3
- module Matchers
4
- class RespondWithMatcher < Remarkable::ActionController::Base #:nodoc:
5
- arguments :block => true
6
-
7
- optional :with, :body, :content_type
8
-
9
- before_assert do
10
- @response = @subject.respond_to?(:response) ? @subject.response : @subject
11
- @controller = @spec.instance_variable_get('@controller')
12
- end
13
-
14
- before_assert :evaluate_content_type, :evaluate_body
15
-
16
- assertions :status_matches?, :body_matches?, :content_type_matches?
17
-
18
- protected
19
-
20
- def status_matches?
21
- return true unless @options[:with] # only continue if not nil
22
-
23
- case @options[:with]
24
- when :success, :missing, :redirect, :error
25
- @response.send("#{@options[:with]}?")
26
- when Fixnum
27
- @response.response_code == @options[:with]
28
- when Symbol, String
29
- @response.response_code == ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[@options[:with].to_sym]
30
- when Range
31
- @options[:with].include?(@response.response_code)
32
- else
33
- raise ArgumentError, "I don't know how to interpret status #{@options[:with].inspect}, " <<
34
- "please give me a Fixnum, Symbol, String or Range."
35
- end
36
- end
37
-
38
- def body_matches?
39
- return true unless @options.key?(:body)
40
- assert_contains(@response.body, @options[:body])
41
- end
42
-
43
- def content_type_matches?
44
- return true unless @options.key?(:content_type)
45
- assert_contains(@response.content_type, @options[:content_type])
46
- end
47
-
48
- def evaluate_content_type
49
- return unless @options.key?(:content_type)
50
-
51
- @options[:content_type] = case @options[:content_type]
52
- when Symbol
53
- Mime::Type.lookup_by_extension(@options[:content_type].to_s).to_s
54
- when Regexp
55
- @options[:content_type]
56
- else
57
- @options[:content_type].to_s
58
- end
1
+ module Remarkable
2
+ module ActionController
3
+ module Matchers
4
+ class RespondWithMatcher < Remarkable::ActionController::Base #:nodoc:
5
+ arguments :block => true
6
+
7
+ optional :with, :body, :content_type
8
+
9
+ before_assert do
10
+ @response = @subject.respond_to?(:response) ? @subject.response : @subject
11
+ @controller = @spec.instance_variable_get('@controller')
12
+ end
13
+
14
+ before_assert :evaluate_content_type, :evaluate_body
15
+
16
+ assertions :status_matches?, :body_matches?, :content_type_matches?
17
+
18
+ protected
19
+
20
+ def status_matches?
21
+ return true unless @options[:with] # only continue if not nil
22
+
23
+ case @options[:with]
24
+ when :success, :missing, :redirect, :error
25
+ @response.send("#{@options[:with]}?")
26
+ when Fixnum
27
+ @response.response_code == @options[:with]
28
+ when Symbol, String
29
+ @response.response_code == ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[@options[:with].to_sym]
30
+ when Range
31
+ @options[:with].include?(@response.response_code)
32
+ else
33
+ raise ArgumentError, "I don't know how to interpret status #{@options[:with].inspect}, " <<
34
+ "please give me a Fixnum, Symbol, String or Range."
35
+ end
36
+ end
37
+
38
+ def body_matches?
39
+ return true unless @options.key?(:body)
40
+ assert_contains(@response.body, @options[:body])
41
+ end
42
+
43
+ def content_type_matches?
44
+ return true unless @options.key?(:content_type)
45
+ assert_contains(@response.content_type, @options[:content_type])
46
+ end
47
+
48
+ def evaluate_content_type
49
+ return unless @options.key?(:content_type)
50
+
51
+ @options[:content_type] = case @options[:content_type]
52
+ when Symbol
53
+ Mime::Type.lookup_by_extension(@options[:content_type].to_s).to_s
54
+ when Regexp
55
+ @options[:content_type]
56
+ else
57
+ @options[:content_type].to_s
58
+ end
59
59
  end
60
60
 
61
61
  def evaluate_body
62
- if @options.key?(:body) || @block
63
- value = @options.key?(:body) ? @options[:body] : @block
64
- value = @spec.instance_eval(&value) if value.is_a?(Proc)
65
- @options[:body] = value
62
+ if @options.key?(:body) || @block
63
+ value = @options.key?(:body) ? @options[:body] : @block
64
+ value = @spec.instance_eval(&value) if value.is_a?(Proc)
65
+ @options[:body] = value
66
+ end
67
+ end
68
+
69
+ def interpolation_options
70
+ if @response
71
+ { :actual_body => @response.body.inspect,
72
+ :actual_status => @response.response_code.inspect,
73
+ :actual_content_type => @response.content_type.inspect }
74
+ else
75
+ { }
66
76
  end
67
- end
68
-
69
- def interpolation_options
70
- if @response
71
- { :actual_body => @response.body.inspect,
72
- :actual_status => @response.response_code.inspect,
73
- :actual_content_type => @response.content_type.inspect }
74
- else
75
- { }
76
- end
77
- end
78
-
79
- end
80
-
81
- # Passes if the response has the given status. Status can be a Symbol lik
82
- # :success, :missing, :redirect and :error. Can be also a Fixnum, Range o
83
- # any other symbol which matches to any of Rails status codes.
84
- #
85
- # == Options
86
- #
87
- # * <tt>:body</tt> - The body of the response. It accepts strings and or
88
- # regular expressions. Altought you might be running your tests without
89
- # integrating your views, this is useful when rendering :xml or :text.
90
- #
91
- # * <tt>:content_type</tt> - The content type of the response.
92
- # It accepts strings ('application/rss+xml'), mime constants (Mime::RSS),
93
- # symbols (:rss) and regular expressions /rss/.
94
- #
95
- # == Examples
96
- #
97
- # should_respond_with :success
98
- # should_respond_with :error, :body => /System error/
99
- # should_respond_with 301, :content_type => Mime::XML
100
- # should_respond_with 300..399, :content_type => Mime::XML
101
- #
102
- # it { should respond_with(:success) }
103
- # it { should respond_with(:error).body(/System error/) }
104
- # it { should respond_with(301).content_type(Mime::XML) }
105
- # it { should respond_with(300..399).content_type(Mime::XML) }
106
- #
107
- def respond_with(*args, &block)
77
+ end
78
+
79
+ end
80
+
81
+ # Passes if the response has the given status. Status can be a Symbol lik
82
+ # :success, :missing, :redirect and :error. Can be also a Fixnum, Range o
83
+ # any other symbol which matches to any of Rails status codes.
84
+ #
85
+ # == Options
86
+ #
87
+ # * <tt>:body</tt> - The body of the response. It accepts strings and or
88
+ # regular expressions. Altought you might be running your tests without
89
+ # integrating your views, this is useful when rendering :xml or :text.
90
+ #
91
+ # * <tt>:content_type</tt> - The content type of the response.
92
+ # It accepts strings ('application/rss+xml'), mime constants (Mime::RSS),
93
+ # symbols (:rss) and regular expressions /rss/.
94
+ #
95
+ # == Examples
96
+ #
97
+ # should_respond_with :success
98
+ # should_respond_with :error, :body => /System error/
99
+ # should_respond_with 301, :content_type => Mime::XML
100
+ # should_respond_with 300..399, :content_type => Mime::XML
101
+ #
102
+ # it { should respond_with(:success) }
103
+ # it { should respond_with(:error).body(/System error/) }
104
+ # it { should respond_with(301).content_type(Mime::XML) }
105
+ # it { should respond_with(300..399).content_type(Mime::XML) }
106
+ #
107
+ def respond_with(*args, &block)
108
108
  options = args.extract_options!
109
- options.merge!(:with => args.first)
110
- RespondWithMatcher.new(options, &block).spec(self)
111
- end
112
-
113
- # This is just a shortcut for respond_with :body => body. Check respond_with
114
- # for more information.
115
- #
116
- def respond_with_body(*args, &block)
109
+ options.merge!(:with => args.first)
110
+ RespondWithMatcher.new(options, &block).spec(self)
111
+ end
112
+
113
+ # This is just a shortcut for respond_with :body => body. Check respond_with
114
+ # for more information.
115
+ #
116
+ def respond_with_body(*args, &block)
117
117
  options = args.extract_options!
118
118
  # Since body can be also given as block, only merge if any arguments was
119
119
  # actually sent.
120
120
  options.merge!(:body => args.first) unless args.empty?
121
- RespondWithMatcher.new(options, &block).spec(self)
122
- end
123
-
124
- # This is just a shortcut for respond_with :content_type => content_type.
125
- # It's also used for Shoulda compatibility. Check respond_with for more
126
- # information.
127
- #
128
- def respond_with_content_type(*args, &block)
121
+ RespondWithMatcher.new(options, &block).spec(self)
122
+ end
123
+
124
+ # This is just a shortcut for respond_with :content_type => content_type.
125
+ # It's also used for Shoulda compatibility. Check respond_with for more
126
+ # information.
127
+ #
128
+ def respond_with_content_type(*args, &block)
129
129
  options = args.extract_options!
130
- options.merge!(:content_type => args.first)
131
- RespondWithMatcher.new(options, &block).spec(self)
132
- end
133
-
134
- end
135
- end
136
- end
130
+ options.merge!(:content_type => args.first)
131
+ RespondWithMatcher.new(options, &block).spec(self)
132
+ end
133
+
134
+ end
135
+ end
136
+ end