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
@@ -3,86 +3,86 @@ module Remarkable
3
3
  module Matchers
4
4
  class AssignToMatcher < Remarkable::ActionController::Base #:nodoc:
5
5
  arguments :collection => :names, :as => :name, :block => :block
6
-
7
- optional :with, :with_kind_of
8
- collection_assertions :assigned_value?, :is_kind_of?, :is_equal_value?
9
-
10
- before_assert :evaluate_expected_value
11
-
12
- default_options :with_expectations => true
6
+
7
+ optional :with, :with_kind_of
8
+ collection_assertions :assigned_value?, :is_kind_of?, :is_equal_value?
9
+
10
+ before_assert :evaluate_expected_value
11
+
12
+ default_options :with_expectations => true
13
13
 
14
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
-
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
60
  end
61
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
- #
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
76
  # * <tt>:with_kind_of</tt> - The expected class of the assign.
77
77
  #
78
78
  # == Examples
79
- #
80
- # should_assign_to :user, :with_kind_of => User
79
+ #
80
+ # should_assign_to :user, :with_kind_of => User
81
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)) }
82
+ # should_assign_to(:user){ users(:first) }
83
+ #
84
+ # it { should assign_to(:user) }
85
+ # it { should assign_to(:user, :with => users(:first)) }
86
86
  # it { should assign_to(:user, :with_kind_of => User) }
87
87
  #
88
88
  def assign_to(*args, &block)
@@ -1,39 +1,39 @@
1
1
  module Remarkable
2
2
  module ActionController
3
- module Matchers
4
- # Do not inherit from ActionController::Base since it don't need all macro stubs behavior.
3
+ module Matchers
4
+ # Do not inherit from ActionController::Base since it don't need all macro stubs behavior.
5
5
  class FilterParamsMatcher < Remarkable::Base #:nodoc:
6
6
  arguments :collection => :params, :as => :param
7
-
8
- assertions :respond_to_filter_params?
9
- collection_assertions :is_filtered?
10
-
7
+
8
+ assertions :respond_to_filter_params?
9
+ collection_assertions :is_filtered?
10
+
11
11
  protected
12
-
13
- def respond_to_filter_params?
12
+
13
+ def respond_to_filter_params?
14
14
  @subject.respond_to?(:filter_parameters)
15
15
  end
16
16
 
17
- def is_filtered?
18
- filtered = @subject.send(:filter_parameters, { @param.to_s => @param.to_s })
17
+ def is_filtered?
18
+ filtered = @subject.send(:filter_parameters, { @param.to_s => @param.to_s })
19
19
  filtered[@param.to_s] == '[FILTERED]'
20
- end
21
-
20
+ end
21
+
22
22
  end
23
23
 
24
- # Checks if the controller filters the given params.
25
- #
24
+ # Checks if the controller filters the given params.
25
+ #
26
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) }
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
33
  #
34
34
  def filter_params(*params)
35
35
  FilterParamsMatcher.new(*params).spec(self)
36
- end
36
+ end
37
37
  alias :filter_param :filter_params
38
38
 
39
39
  end
@@ -1,118 +1,118 @@
1
1
  module Remarkable
2
2
  module ActionController
3
3
  module Matchers
4
- class RedirectToMatcher < Remarkable::ActionController::Base #:nodoc:
5
- include ::ActionController::StatusCodes
6
-
7
- arguments :expected, :block => :block
8
- optional :with
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
4
+ class RedirectToMatcher < Remarkable::ActionController::Base #:nodoc:
5
+ include ::ActionController::StatusCodes
6
+
7
+ arguments :expected, :block => :block
8
+ optional :with
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
116
 
117
117
  end
118
118
  end