remarkable_rails 3.0.1 → 3.0.2

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