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,94 +1,94 @@
1
- module Remarkable
2
- module ActionController
3
- module Matchers
4
- class AssignToMatcher < Remarkable::ActionController::Base #:nodoc:
5
- arguments :collection => :names, :as => :name, :block => true
6
-
1
+ module Remarkable
2
+ module ActionController
3
+ module Matchers
4
+ class AssignToMatcher < Remarkable::ActionController::Base #:nodoc:
5
+ arguments :collection => :names, :as => :name, :block => true
6
+
7
7
  optional :with, :block => true
8
8
  optional :with_kind_of
9
-
10
- collection_assertions :assigned_value?, :is_kind_of?, :is_equal_value?
11
-
12
- before_assert :evaluate_expected_value
13
-
14
- protected
15
-
16
- def assigned_value?
17
- assigns.key?(@name)
18
- end
19
-
20
- def is_kind_of?
21
- return true unless @options[:with_kind_of]
22
- return assigns[@name].kind_of?(@options[:with_kind_of])
23
- end
24
-
25
- # Returns true if :with is not given and no block is given.
26
- # In case :with is a proc or a block is given, we evaluate it in the
27
- # @spec scope.
28
- #
29
- def is_equal_value?
30
- return true unless value_to_compare?
31
- assigns[@name] == @options[:with]
32
- end
33
-
34
- def assigns
35
- @subject.response.template.assigns.with_indifferent_access
36
- end
37
-
38
- def value_to_compare?
39
- @options.key?(:with) || @block
40
- end
41
-
42
- # Update interpolation options
43
- def interpolation_options
44
- if @subject && @subject.response
45
- { :assign_inspect => assigns[@name].inspect, :assign_class => assigns[@name].class.name }
46
- else
47
- { }
48
- end
49
- end
50
-
51
- # Evaluate procs before assert to avoid them appearing in descriptions.
52
- def evaluate_expected_value
53
- if value_to_compare?
54
- value = @options.key?(:with) ? @options[:with] : @block
55
- value = @spec.instance_eval(&value) if value.is_a?(Proc)
56
- @options[:with] = value
57
- end
58
- end
59
-
60
- end
61
-
62
- # Checks if the controller assigned the variables given by name. If you
63
- # want to check that a variable is not being assigned, please do:
64
- #
65
- # should_not_assign_to(:user)
66
- #
67
- # If you want to assure that a variable is being assigned to nil, do instead:
68
- #
69
- # should_assign_to(:user).with(nil)
70
- #
71
- # == Options
72
- #
73
- # * <tt>:with</tt> - The value to compare the assign.
74
- # It can be also be supplied as proc or as a block (see examples below)
75
- #
76
- # * <tt>:with_kind_of</tt> - The expected class of the assign.
77
- #
78
- # == Examples
79
- #
80
- # should_assign_to :user, :with_kind_of => User
81
- # should_assign_to :user, :with => proc{ users(:first) }
82
- # should_assign_to(:user){ users(:first) }
83
- #
84
- # it { should assign_to(:user) }
85
- # it { should assign_to(:user, :with => users(:first)) }
86
- # it { should assign_to(:user, :with_kind_of => User) }
87
- #
88
- def assign_to(*args, &block)
89
- AssignToMatcher.new(*args, &block).spec(self)
90
- end
91
-
92
- end
93
- end
94
- end
9
+
10
+ collection_assertions :assigned_value?, :is_kind_of?, :is_equal_value?
11
+
12
+ before_assert :evaluate_expected_value
13
+
14
+ protected
15
+
16
+ def assigned_value?
17
+ assigns.key?(@name)
18
+ end
19
+
20
+ def is_kind_of?
21
+ return true unless @options[:with_kind_of]
22
+ return assigns[@name].kind_of?(@options[:with_kind_of])
23
+ end
24
+
25
+ # Returns true if :with is not given and no block is given.
26
+ # In case :with is a proc or a block is given, we evaluate it in the
27
+ # @spec scope.
28
+ #
29
+ def is_equal_value?
30
+ return true unless value_to_compare?
31
+ assigns[@name] == @options[:with]
32
+ end
33
+
34
+ def assigns
35
+ @subject.response.template.assigns.with_indifferent_access
36
+ end
37
+
38
+ def value_to_compare?
39
+ @options.key?(:with) || @block
40
+ end
41
+
42
+ # Update interpolation options
43
+ def interpolation_options
44
+ if @subject && @subject.response
45
+ { :assign_inspect => assigns[@name].inspect, :assign_class => assigns[@name].class.name }
46
+ else
47
+ { }
48
+ end
49
+ end
50
+
51
+ # Evaluate procs before assert to avoid them appearing in descriptions.
52
+ def evaluate_expected_value
53
+ if value_to_compare?
54
+ value = @options.key?(:with) ? @options[:with] : @block
55
+ value = @spec.instance_eval(&value) if value.is_a?(Proc)
56
+ @options[:with] = value
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ # Checks if the controller assigned the variables given by name. If you
63
+ # want to check that a variable is not being assigned, please do:
64
+ #
65
+ # should_not_assign_to(:user)
66
+ #
67
+ # If you want to assure that a variable is being assigned to nil, do instead:
68
+ #
69
+ # should_assign_to(:user).with(nil)
70
+ #
71
+ # == Options
72
+ #
73
+ # * <tt>:with</tt> - The value to compare the assign.
74
+ # It can be also be supplied as proc or as a block (see examples below)
75
+ #
76
+ # * <tt>:with_kind_of</tt> - The expected class of the assign.
77
+ #
78
+ # == Examples
79
+ #
80
+ # should_assign_to :user, :with_kind_of => User
81
+ # should_assign_to :user, :with => proc{ users(:first) }
82
+ # should_assign_to(:user){ users(:first) }
83
+ #
84
+ # it { should assign_to(:user) }
85
+ # it { should assign_to(:user, :with => users(:first)) }
86
+ # it { should assign_to(:user, :with_kind_of => User) }
87
+ #
88
+ def assign_to(*args, &block)
89
+ AssignToMatcher.new(*args, &block).spec(self)
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -1,41 +1,41 @@
1
- module Remarkable
2
- module ActionController
3
- module Matchers
4
- # Do not inherit from ActionController::Base since it don't need all macro stubs behavior.
5
- class FilterParamsMatcher < Remarkable::Base #:nodoc:
6
- arguments :collection => :params, :as => :param
7
-
8
- assertions :respond_to_filter_params?
9
- collection_assertions :is_filtered?
10
-
11
- protected
12
-
13
- def respond_to_filter_params?
14
- @subject.respond_to?(:filter_parameters)
15
- end
16
-
17
- def is_filtered?
18
- filtered = @subject.send(:filter_parameters, { @param.to_s => @param.to_s })
19
- filtered[@param.to_s] == '[FILTERED]'
20
- end
21
-
22
- end
23
-
24
- # Checks if the controller filters the given params.
25
- #
26
- # == Examples
27
- #
28
- # should_filter_params :password
29
- # should_not_filter_params :username
30
- #
31
- # it { should filter_params(:password) }
32
- # it { should_not filter_params(:username) }
33
- #
34
- def filter_params(*params, &block)
35
- FilterParamsMatcher.new(*params, &block).spec(self)
36
- end
37
- alias :filter_param :filter_params
38
-
39
- end
40
- end
41
- end
1
+ module Remarkable
2
+ module ActionController
3
+ module Matchers
4
+ # Do not inherit from ActionController::Base since it don't need all macro stubs behavior.
5
+ class FilterParamsMatcher < Remarkable::Base #:nodoc:
6
+ arguments :collection => :params, :as => :param
7
+
8
+ assertions :respond_to_filter_params?
9
+ collection_assertions :is_filtered?
10
+
11
+ protected
12
+
13
+ def respond_to_filter_params?
14
+ @subject.respond_to?(:filter_parameters)
15
+ end
16
+
17
+ def is_filtered?
18
+ filtered = @subject.send(:filter_parameters, { @param.to_s => @param.to_s })
19
+ filtered[@param.to_s] == '[FILTERED]'
20
+ end
21
+
22
+ end
23
+
24
+ # Checks if the controller filters the given params.
25
+ #
26
+ # == Examples
27
+ #
28
+ # should_filter_params :password
29
+ # should_not_filter_params :username
30
+ #
31
+ # it { should filter_params(:password) }
32
+ # it { should_not filter_params(:username) }
33
+ #
34
+ def filter_params(*params, &block)
35
+ FilterParamsMatcher.new(*params, &block).spec(self)
36
+ end
37
+ alias :filter_param :filter_params
38
+
39
+ end
40
+ end
41
+ end
@@ -1,119 +1,119 @@
1
- module Remarkable
2
- module ActionController
3
- module Matchers
4
- class RedirectToMatcher < Remarkable::ActionController::Base #:nodoc:
5
- include ::ActionController::StatusCodes
6
-
7
- arguments :expected, :block => true
8
- optional :with, :block => true
9
-
10
- assertions :redirected?, :status_matches?, :url_matches?
11
-
12
- before_assert :evaluate_expected_value
13
-
14
- before_assert do
15
- @response = @subject.respond_to?(:response) ? @subject.response : @subject
16
- @request = @response.instance_variable_get('@request')
17
- end
18
-
19
- protected
20
-
21
- def redirected?
22
- @response.redirect?
23
- end
24
-
25
- def status_matches?
26
- return true unless @options.key?(:with)
27
-
28
- actual_status = interpret_status(@response.response_code)
29
- expected_status = interpret_status(@options[:with])
30
-
31
- return actual_status == expected_status, :status => @response.response_code.inspect
32
- end
33
-
34
- def url_matches?
35
- @actual = @response.redirect_url
36
-
37
- if @expected.instance_of?(Hash)
38
- return false unless @actual =~ /^\w+:\/\/#{@request.host}/ && actual_hash
39
- actual_hash == expected_hash
40
- else
41
- @actual == expected_url
42
- end
43
- end
44
-
45
- def actual_hash
46
- hash_from_url @actual
47
- end
48
-
49
- def expected_hash
50
- hash_from_url expected_url
51
- end
52
-
53
- def hash_from_url(url)
54
- query_hash(url).merge(path_hash(url)).with_indifferent_access
55
- end
56
-
57
- def path_hash(url)
58
- path = url.sub(/^\w+:\/\/#{@request.host}(?::\d+)?/, "").split("?", 2)[0]
59
- ::ActionController::Routing::Routes.recognize_path path, { :method => :get }
60
- end
61
-
62
- def query_hash(url)
63
- query = url.split("?", 2)[1] || ""
64
-
65
- if defined?(::Rack::Utils)
66
- ::Rack::Utils.parse_query(query)
67
- else
68
- @request.class.parse_query_parameters(query)
69
- end
70
- end
71
-
72
- def expected_url
73
- case @expected
74
- when Hash
75
- return ::ActionController::UrlRewriter.new(@request, {}).rewrite(@expected)
76
- when :back
77
- return @request.env['HTTP_REFERER']
78
- when %r{^\w+://.*}
79
- return @expected
80
- else
81
- return "http://#{@request.host}" + (@expected.split('')[0] == '/' ? '' : '/') + @expected
82
- end
83
- end
84
-
85
- def interpolation_options
86
- { :expected => @expected.inspect, :actual => @actual.inspect }
87
- end
88
-
89
- def evaluate_expected_value
90
- @expected ||= @block if @block
91
- @expected = @spec.instance_eval(&@expected) if @expected.is_a?(Proc)
92
- end
93
-
94
- end
95
-
96
- # Passes if the response redirects to the given url. The url can be a string,
97
- # a hash or can be supplied as a block (see examples below).
98
- #
99
- # == Options
100
- #
101
- # * <tt>:with</tt> - The status 30X used when redirecting.
102
- #
103
- # == Examples
104
- #
105
- # should_redirect_to{ users_url }
106
- # should_redirect_to(:action => 'index')
107
- # should_not_redirect_to(:controller => 'users', :action => 'new')
108
- #
109
- # it { should redirect_to(users_url).with(302) }
110
- # it { should redirect_to(:action => 'index') }
111
- # it { should_not redirect_to(:controller => 'users', :action => 'new') }
112
- #
113
- def redirect_to(expected=nil, options={}, &block)
114
- RedirectToMatcher.new(expected, options, &block).spec(self)
115
- end
116
-
117
- end
118
- end
119
- end
1
+ module Remarkable
2
+ module ActionController
3
+ module Matchers
4
+ class RedirectToMatcher < Remarkable::ActionController::Base #:nodoc:
5
+ include ::ActionController::StatusCodes
6
+
7
+ arguments :expected, :block => true
8
+ optional :with, :block => true
9
+
10
+ assertions :redirected?, :status_matches?, :url_matches?
11
+
12
+ before_assert :evaluate_expected_value
13
+
14
+ before_assert do
15
+ @response = @subject.respond_to?(:response) ? @subject.response : @subject
16
+ @request = @response.instance_variable_get('@request')
17
+ end
18
+
19
+ protected
20
+
21
+ def redirected?
22
+ @response.redirect?
23
+ end
24
+
25
+ def status_matches?
26
+ return true unless @options.key?(:with)
27
+
28
+ actual_status = interpret_status(@response.response_code)
29
+ expected_status = interpret_status(@options[:with])
30
+
31
+ return actual_status == expected_status, :status => @response.response_code.inspect
32
+ end
33
+
34
+ def url_matches?
35
+ @actual = @response.redirect_url
36
+
37
+ if @expected.instance_of?(Hash)
38
+ return false unless @actual =~ /^\w+:\/\/#{@request.host}/ && actual_hash
39
+ actual_hash == expected_hash
40
+ else
41
+ @actual == expected_url
42
+ end
43
+ end
44
+
45
+ def actual_hash
46
+ hash_from_url @actual
47
+ end
48
+
49
+ def expected_hash
50
+ hash_from_url expected_url
51
+ end
52
+
53
+ def hash_from_url(url)
54
+ query_hash(url).merge(path_hash(url)).with_indifferent_access
55
+ end
56
+
57
+ def path_hash(url)
58
+ path = url.sub(/^\w+:\/\/#{@request.host}(?::\d+)?/, "").split("?", 2)[0]
59
+ ::ActionController::Routing::Routes.recognize_path path, { :method => :get }
60
+ end
61
+
62
+ def query_hash(url)
63
+ query = url.split("?", 2)[1] || ""
64
+
65
+ if defined?(::Rack::Utils)
66
+ ::Rack::Utils.parse_query(query)
67
+ else
68
+ @request.class.parse_query_parameters(query)
69
+ end
70
+ end
71
+
72
+ def expected_url
73
+ case @expected
74
+ when Hash
75
+ return ::ActionController::UrlRewriter.new(@request, {}).rewrite(@expected)
76
+ when :back
77
+ return @request.env['HTTP_REFERER']
78
+ when %r{^\w+://.*}
79
+ return @expected
80
+ else
81
+ return "http://#{@request.host}" + (@expected.split('')[0] == '/' ? '' : '/') + @expected
82
+ end
83
+ end
84
+
85
+ def interpolation_options
86
+ { :expected => @expected.inspect, :actual => @actual.inspect }
87
+ end
88
+
89
+ def evaluate_expected_value
90
+ @expected ||= @block if @block
91
+ @expected = @spec.instance_eval(&@expected) if @expected.is_a?(Proc)
92
+ end
93
+
94
+ end
95
+
96
+ # Passes if the response redirects to the given url. The url can be a string,
97
+ # a hash or can be supplied as a block (see examples below).
98
+ #
99
+ # == Options
100
+ #
101
+ # * <tt>:with</tt> - The status 30X used when redirecting.
102
+ #
103
+ # == Examples
104
+ #
105
+ # should_redirect_to{ users_url }
106
+ # should_redirect_to(:action => 'index')
107
+ # should_not_redirect_to(:controller => 'users', :action => 'new')
108
+ #
109
+ # it { should redirect_to(users_url).with(302) }
110
+ # it { should redirect_to(:action => 'index') }
111
+ # it { should_not redirect_to(:controller => 'users', :action => 'new') }
112
+ #
113
+ def redirect_to(expected=nil, options={}, &block)
114
+ RedirectToMatcher.new(expected, options, &block).spec(self)
115
+ end
116
+
117
+ end
118
+ end
119
+ end