remarkable_rails 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
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,80 +1,80 @@
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 RouteMatcher < Remarkable::Base #:nodoc:
6
- arguments :method, :path
7
-
6
+ arguments :method, :path
7
+
8
8
  assertions :map_to_path?, :generate_params?
9
-
10
- before_assert do
11
- @options[:controller] ||= controller_name
12
-
13
- @populated_path = @path.dup
9
+
10
+ before_assert do
11
+ @options[:controller] ||= controller_name
12
+
13
+ @populated_path = @path.dup
14
14
 
15
15
  @options.each do |key, value|
16
16
  @options[key] = value.to_param if value.respond_to?(:to_param)
17
17
  @populated_path.gsub!(key.inspect, value.to_s)
18
18
  end
19
19
 
20
- ::ActionController::Routing::Routes.reload if ::ActionController::Routing::Routes.empty?
21
- end
20
+ ::ActionController::Routing::Routes.reload if ::ActionController::Routing::Routes.empty?
21
+ end
22
22
 
23
23
  private
24
-
24
+
25
25
  def map_to_path?
26
26
  route_for = ::ActionController::Routing::Routes.generate(@options) rescue nil
27
27
  return route_for == @populated_path, :actual => route_for.inspect
28
28
  end
29
-
29
+
30
30
  def generate_params?
31
31
  params_from = ::ActionController::Routing::Routes.recognize_path(@populated_path, :method => @method.to_sym)
32
32
  return params_from == @options, :actual => params_from.inspect
33
- end
34
-
35
- # First tries to get the controller name from the subject, then from
36
- # the spec class using controller class or finally, from the described
37
- # class.
38
- #
39
- # We have to try the described class because we don't have neither the
40
- # subject or the controller class in the RoutingExampleGroup.
41
- #
42
- def controller_name
43
- spec_class = @spec.class unless @spec.class == Class
44
-
45
- controller = if @subject && @subject.class.ancestors.include?(::ActionController::Base)
46
- @subject.class
47
- elsif spec_class.respond_to?(:controller_class)
48
- spec_class.controller_class
49
- elsif spec_class.respond_to?(:described_class)
50
- spec_class.described_class
51
- end
52
-
53
- if controller && controller.ancestors.include?(::ActionController::Base)
54
- controller.name.gsub(/Controller$/, '').tableize
55
- else
56
- raise ArgumentError, "I cannot guess the controller name in route. Please supply :controller as option"
57
- end
58
- end
59
-
60
- def interpolation_options
61
- { :options => @options.inspect, :method => @method.to_s.upcase, :path => @path.inspect }
62
- end
63
-
33
+ end
34
+
35
+ # First tries to get the controller name from the subject, then from
36
+ # the spec class using controller class or finally, from the described
37
+ # class.
38
+ #
39
+ # We have to try the described class because we don't have neither the
40
+ # subject or the controller class in the RoutingExampleGroup.
41
+ #
42
+ def controller_name
43
+ spec_class = @spec.class unless @spec.class == Class
44
+
45
+ controller = if @subject && @subject.class.ancestors.include?(::ActionController::Base)
46
+ @subject.class
47
+ elsif spec_class.respond_to?(:controller_class)
48
+ spec_class.controller_class
49
+ elsif spec_class.respond_to?(:described_class)
50
+ spec_class.described_class
51
+ end
52
+
53
+ if controller && controller.ancestors.include?(::ActionController::Base)
54
+ controller.name.gsub(/Controller$/, '').tableize
55
+ else
56
+ raise ArgumentError, "I cannot guess the controller name in route. Please supply :controller as option"
57
+ end
58
+ end
59
+
60
+ def interpolation_options
61
+ { :options => @options.inspect, :method => @method.to_s.upcase, :path => @path.inspect }
62
+ end
63
+
64
64
  end
65
65
 
66
- # Assert route generation AND route recognition.
67
- #
66
+ # Assert route generation AND route recognition.
67
+ #
68
68
  # == Examples
69
- #
69
+ #
70
70
  # # autodetects the :controller
71
71
  # should_route :get, '/posts', :action => :index
72
72
  #
73
73
  # # explicitly specify :controller
74
- # should_route :post, '/posts', :controller => :posts, :action => :create
74
+ # should_route :post, '/posts', :controller => :posts, :action => :create
75
75
  #
76
76
  # # non-string parameter
77
- # should_route :get, '/posts/1', :controller => :posts, :action => :show, :id => 1
77
+ # should_route :get, '/posts/1', :controller => :posts, :action => :show, :id => 1
78
78
  #
79
79
  # # string-parameter
80
80
  # should_route :put, '/posts/1', :controller => :posts, :action => :update, :id => "1"
@@ -85,9 +85,9 @@ module Remarkable
85
85
  # should_route :get, '/users/5/posts', :controller => :posts, :action => :index, :user_id => 5
86
86
  # should_route :post, '/users/5/posts', :controller => :posts, :action => :create, :user_id => 5
87
87
  #
88
- def route(*params)
88
+ def route(*params)
89
89
  RouteMatcher.new(*params).spec(self)
90
- end
90
+ end
91
91
 
92
92
  end
93
93
  end
@@ -1,108 +1,108 @@
1
1
  module Remarkable
2
2
  module ActionController
3
3
  module Matchers
4
- class SetSessionMatcher < Remarkable::ActionController::Base #:nodoc:
5
- arguments :collection => :keys, :as => :key, :block => :block
6
-
7
- optional :to
8
-
9
- assertion :is_not_empty?, :contains_value?
10
- collection_assertions :assigned_value?, :is_equal_value?
11
-
12
- before_assert :evaluate_expected_value
13
-
14
- private
15
-
16
- # When no keys are given:
17
- #
18
- # should set_session
19
- #
20
- # We check if the session is not empty.
21
- #
22
- def is_not_empty?
23
- !(@keys.empty? && session.empty?)
24
- end
25
-
26
- # When no keys are given and a comparision value is given:
27
- #
28
- # should set_session.to(1)
29
- #
30
- # We check if any of the session data contains the given value.
31
- #
32
- def contains_value?
33
- return true unless @keys.empty? && value_to_compare?
34
- assert_contains(session.values, @options[:to])
35
- end
36
-
37
- def assigned_value?
38
- session.key?(@key)
39
- end
40
-
41
- # Returns true if :to is not given and no block is given.
42
- # In case :to is a proc or a block is given, we evaluate it in the
43
- # @spec scope.
44
- #
45
- def is_equal_value?
46
- return true unless value_to_compare?
47
- session[@key] == @options[:to]
48
- end
49
-
50
- def session
51
- raw_session.with_indifferent_access.except(:flash)
52
- end
53
-
54
- def raw_session
55
- @subject ? @subject.response.session.data : {}
56
- end
57
-
58
- def value_to_compare?
59
- @options.key?(:to) || @block
60
- end
61
-
62
- def interpolation_options
63
- { :session_inspect => raw_session.except('flash').symbolize_keys!.inspect }
64
- end
65
-
66
- # Evaluate procs before assert to avoid them appearing in descriptions.
67
- def evaluate_expected_value
68
- if value_to_compare?
69
- value = @options.key?(:to) ? @options[:to] : @block
70
- value = @spec.instance_eval(&value) if value.is_a?(Proc)
71
- @options[:to] = value
72
- end
73
- end
74
-
75
- end
76
-
77
- # Ensures that a session keys were set. If you want to check that a variable
78
- # is not being set, please do:
79
- #
80
- # should_not_set_session(:user)
81
- #
82
- # If you want to assure that a variable is being set to nil, do instead:
83
- #
84
- # should_set_session(:user).to(nil)
85
- #
86
- # == Options
87
- #
88
- # * <tt>:to</tt> - The value to compare the session key.
89
- # It accepts procs and be also given as a block (see examples below).
4
+ class SetSessionMatcher < Remarkable::ActionController::Base #:nodoc:
5
+ arguments :collection => :keys, :as => :key, :block => :block
6
+
7
+ optional :to
8
+
9
+ assertion :is_not_empty?, :contains_value?
10
+ collection_assertions :assigned_value?, :is_equal_value?
11
+
12
+ before_assert :evaluate_expected_value
13
+
14
+ private
15
+
16
+ # When no keys are given:
17
+ #
18
+ # should set_session
19
+ #
20
+ # We check if the session is not empty.
21
+ #
22
+ def is_not_empty?
23
+ !(@keys.empty? && session.empty?)
24
+ end
25
+
26
+ # When no keys are given and a comparision value is given:
27
+ #
28
+ # should set_session.to(1)
29
+ #
30
+ # We check if any of the session data contains the given value.
31
+ #
32
+ def contains_value?
33
+ return true unless @keys.empty? && value_to_compare?
34
+ assert_contains(session.values, @options[:to])
35
+ end
36
+
37
+ def assigned_value?
38
+ session.key?(@key)
39
+ end
40
+
41
+ # Returns true if :to is not given and no block is given.
42
+ # In case :to is a proc or a block is given, we evaluate it in the
43
+ # @spec scope.
44
+ #
45
+ def is_equal_value?
46
+ return true unless value_to_compare?
47
+ session[@key] == @options[:to]
48
+ end
49
+
50
+ def session
51
+ raw_session.with_indifferent_access.except(:flash)
52
+ end
53
+
54
+ def raw_session
55
+ @subject ? @subject.response.session.data : {}
56
+ end
57
+
58
+ def value_to_compare?
59
+ @options.key?(:to) || @block
60
+ end
61
+
62
+ def interpolation_options
63
+ { :session_inspect => raw_session.except('flash').symbolize_keys!.inspect }
64
+ end
65
+
66
+ # Evaluate procs before assert to avoid them appearing in descriptions.
67
+ def evaluate_expected_value
68
+ if value_to_compare?
69
+ value = @options.key?(:to) ? @options[:to] : @block
70
+ value = @spec.instance_eval(&value) if value.is_a?(Proc)
71
+ @options[:to] = value
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ # Ensures that a session keys were set. If you want to check that a variable
78
+ # is not being set, please do:
79
+ #
80
+ # should_not_set_session(:user)
81
+ #
82
+ # If you want to assure that a variable is being set to nil, do instead:
83
+ #
84
+ # should_set_session(:user).to(nil)
85
+ #
86
+ # == Options
87
+ #
88
+ # * <tt>:to</tt> - The value to compare the session key.
89
+ # It accepts procs and be also given as a block (see examples below).
90
90
  #
91
91
  # == Examples
92
- #
93
- # should_set_session :user_id, :user
94
- # should_set_session :user_id, :to => 2
95
- # should_set_session :user, :to => proc{ users(:first) }
96
- # should_set_session(:user){ users(:first) }
97
- #
98
- # it { should set_session(:user_id, :user) }
99
- # it { should set_session(:user_id, :to => 2) }
100
- # it { should set_session(:user, :to => users(:first)) }
101
- #
102
- def set_session(*args, &block)
103
- SetSessionMatcher.new(*args, &block).spec(self)
104
- end
105
-
106
- end
107
- end
108
- end
92
+ #
93
+ # should_set_session :user_id, :user
94
+ # should_set_session :user_id, :to => 2
95
+ # should_set_session :user, :to => proc{ users(:first) }
96
+ # should_set_session(:user){ users(:first) }
97
+ #
98
+ # it { should set_session(:user_id, :user) }
99
+ # it { should set_session(:user_id, :to => 2) }
100
+ # it { should set_session(:user, :to => users(:first)) }
101
+ #
102
+ def set_session(*args, &block)
103
+ SetSessionMatcher.new(*args, &block).spec(self)
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -1,55 +1,55 @@
1
- require File.join(File.dirname(__FILE__), 'set_session_matcher')
2
-
1
+ require File.join(File.dirname(__FILE__), 'set_session_matcher')
2
+
3
3
  module Remarkable
4
4
  module ActionController
5
5
  module Matchers
6
- class SetTheFlashMatcher < SetSessionMatcher #:nodoc:
7
-
8
- protected
9
- def session
10
- @subject ? (@subject.response.session['flash'] || {}) : {}
11
- end
12
-
13
- def interpolation_options
14
- { :flash_inspect => session.symbolize_keys!.inspect }
15
- end
16
-
17
- end
18
-
19
- # Ensures that a session keys were set. If you want to check that a flash
20
- # is not being set, please do:
21
- #
22
- # should_not_set_the_flash(:user)
23
- #
24
- # If you want to assure that a flash is being set to nil, do instead:
25
- #
26
- # should_set_the_flash(:user).to(nil)
27
- #
28
- # == Options
29
- #
30
- # * <tt>:to</tt> - The value to compare the flash key. It accepts procs and can also be given as a block (see examples below)
6
+ class SetTheFlashMatcher < SetSessionMatcher #:nodoc:
7
+
8
+ protected
9
+ def session
10
+ @subject ? (@subject.response.session['flash'] || {}) : {}
11
+ end
12
+
13
+ def interpolation_options
14
+ { :flash_inspect => session.symbolize_keys!.inspect }
15
+ end
16
+
17
+ end
18
+
19
+ # Ensures that a session keys were set. If you want to check that a flash
20
+ # is not being set, please do:
21
+ #
22
+ # should_not_set_the_flash(:user)
23
+ #
24
+ # If you want to assure that a flash is being set to nil, do instead:
25
+ #
26
+ # should_set_the_flash(:user).to(nil)
27
+ #
28
+ # == Options
29
+ #
30
+ # * <tt>:to</tt> - The value to compare the flash key. It accepts procs and can also be given as a block (see examples below)
31
31
  #
32
32
  # == Examples
33
- #
34
- # should_set_the_flash
35
- # should_not_set_the_flash
36
- #
37
- # should_set_the_flash :to => 'message'
38
- # should_set_the_flash :notice, :warn
39
- # should_set_the_flash :notice, :to => 'message'
40
- # should_set_the_flash :notice, :to => proc{ 'hi ' + users(:first).name }
41
- # should_set_the_flash(:notice){ 'hi ' + users(:first).name }
42
- #
43
- # it { should set_the_flash }
44
- # it { should set_the_flash.to('message') }
45
- # it { should set_the_flash(:notice, :warn) }
46
- # it { should set_the_flash(:notice, :to => 'message') }
47
- # it { should set_the_flash(:notice, :to => ('hi ' + users(:first).name)) }
48
- #
49
- def set_the_flash(*args, &block)
50
- SetTheFlashMatcher.new(*args, &block).spec(self)
51
- end
52
-
53
- end
54
- end
55
- end
33
+ #
34
+ # should_set_the_flash
35
+ # should_not_set_the_flash
36
+ #
37
+ # should_set_the_flash :to => 'message'
38
+ # should_set_the_flash :notice, :warn
39
+ # should_set_the_flash :notice, :to => 'message'
40
+ # should_set_the_flash :notice, :to => proc{ 'hi ' + users(:first).name }
41
+ # should_set_the_flash(:notice){ 'hi ' + users(:first).name }
42
+ #
43
+ # it { should set_the_flash }
44
+ # it { should set_the_flash.to('message') }
45
+ # it { should set_the_flash(:notice, :warn) }
46
+ # it { should set_the_flash(:notice, :to => 'message') }
47
+ # it { should set_the_flash(:notice, :to => ('hi ' + users(:first).name)) }
48
+ #
49
+ def set_the_flash(*args, &block)
50
+ SetTheFlashMatcher.new(*args, &block).spec(self)
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -1,7 +1,7 @@
1
1
  module Remarkable
2
2
  module ActionView
3
3
  class Base < Remarkable::Base
4
-
4
+
5
5
  end
6
6
  end
7
7
  end
@@ -1,18 +1,18 @@
1
- module Remarkable
2
- module ActionView
3
- end
4
- end
5
-
6
- dir = File.dirname(__FILE__)
7
- require File.join(dir, 'action_view', 'base')
8
-
1
+ module Remarkable
2
+ module ActionView
3
+ end
4
+ end
5
+
6
+ dir = File.dirname(__FILE__)
7
+ require File.join(dir, 'action_view', 'base')
8
+
9
9
  # Load matchers
10
- Dir[File.join(dir, 'action_view', 'matchers', '*.rb')].each do |file|
10
+ Dir[File.join(dir, 'action_view', 'matchers', '*.rb')].each do |file|
11
11
  require file
12
- end
13
-
14
- # Iinclude matchers in Spec::Rails
15
- if defined?(Spec::Rails)
16
- Remarkable.include_matchers!(Remarkable::ActionView, Spec::Rails::Example::FunctionalExampleGroup)
17
- end
18
-
12
+ end
13
+
14
+ # Iinclude matchers in Spec::Rails
15
+ if defined?(Spec::Rails)
16
+ Remarkable.include_matchers!(Remarkable::ActionView, Spec::Rails::Example::FunctionalExampleGroup)
17
+ end
18
+
@@ -12,8 +12,8 @@ if defined?(ActiveRecord::Base)
12
12
  end
13
13
  end
14
14
 
15
- # Include Remarkable ActiveRecord matcher in appropriate ExampleGroup
15
+ # Include Remarkable ActiveRecord matcher in appropriate ExampleGroup
16
16
  if defined?(Spec::Rails)
17
- Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Rails::Example::ModelExampleGroup)
17
+ Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Rails::Example::ModelExampleGroup)
18
18
  end
19
19
  end