benhutton-remarkable_rails 4.0.0.alpha4

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.
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), 'set_session_matcher')
2
+
3
+ module Remarkable
4
+ module ActionController
5
+ module Matchers
6
+ class SetCookiesMatcher < SetSessionMatcher #:nodoc:
7
+
8
+ # For cookies to work properly, we have:
9
+ #
10
+ # On Rails 2.1.2 and 2.2.2:
11
+ #
12
+ # 1. Wrap :to values in an array;
13
+ # 2. When :to is false or nil, make it be an empty array;
14
+ # 3. Convert all keys to string.
15
+ #
16
+ # On Rails 2.3.2:
17
+ #
18
+ # 1. Return nil if nil, join when array or convert to string;
19
+ # 2. Convert all keys to string.
20
+ #
21
+ before_assert do
22
+ if @options.key?(:to)
23
+ if @subject.request.env.key?("rack.input")
24
+ @options[:to] = case @options[:to]
25
+ when nil
26
+ nil
27
+ when Array
28
+ @options[:to].join('&')
29
+ else
30
+ @options[:to].to_s
31
+ end
32
+ else
33
+ @options[:to] = @options[:to] ? Array(@options[:to]) : []
34
+ end
35
+ end
36
+
37
+ @keys.collect!(&:to_s)
38
+ end
39
+
40
+ protected
41
+ def session
42
+ @subject ? (@subject.response.cookies || {}) : {}
43
+ end
44
+
45
+ def interpolation_options
46
+ { :cookies_inspect => session.symbolize_keys!.inspect }
47
+ end
48
+
49
+ end
50
+
51
+ # Ensures that the given cookie keys were set. If you want to check that
52
+ # a cookie is not being set, just do:
53
+ #
54
+ # should_not_set_cookies :user
55
+ #
56
+ # If you want to assure that a cookie is being set to nil, do instead:
57
+ #
58
+ # should_set_cookies :user, :to => nil
59
+ #
60
+ # Note: this method is also aliased as <tt>set_cookie</tt>.
61
+ #
62
+ # == Options
63
+ #
64
+ # * <tt>:to</tt> - The value to compare the session key.
65
+ # It accepts procs and be also given as a block (see examples below).
66
+ #
67
+ # == Examples
68
+ #
69
+ # should_set_cookies :user_id, :user
70
+ # should_set_cookies :user_id, :to => 2
71
+ # should_set_cookies :user, :to => proc{ users(:first) }
72
+ # should_set_cookies(:user){ users(:first) }
73
+ #
74
+ # it { should set_cookies(:user_id, :user) }
75
+ # it { should set_cookies(:user_id, :to => 2) }
76
+ # it { should set_cookies(:user, :to => users(:first)) }
77
+ #
78
+ def set_cookies(*args, &block)
79
+ SetCookiesMatcher.new(*args, &block).spec(self)
80
+ end
81
+ alias :set_cookie :set_cookies
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,108 @@
1
+ module Remarkable
2
+ module ActionController
3
+ module Matchers
4
+ class SetSessionMatcher < Remarkable::ActionController::Base #:nodoc:
5
+ arguments :collection => :keys, :as => :key, :block => true
6
+
7
+ optional :to, :block => true
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
+ assert_contains([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 the given session keys were set. If you want to check that
78
+ # a variable is not being set, just 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
+ #
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
@@ -0,0 +1,56 @@
1
+ require File.join(File.dirname(__FILE__), 'set_session_matcher')
2
+
3
+ module Remarkable
4
+ module ActionController
5
+ module Matchers
6
+ class SetTheFlashMatcher < SetSessionMatcher #:nodoc:
7
+
8
+ protected
9
+ def session
10
+ @subject ? (@subject.request.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 flash message is being set. If you want to check that a
20
+ # flash is not being set, just 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.
31
+ # It accepts procs and can also be given as a block (see examples below)
32
+ #
33
+ # == Examples
34
+ #
35
+ # should_set_the_flash
36
+ # should_not_set_the_flash
37
+ #
38
+ # should_set_the_flash :to => 'message'
39
+ # should_set_the_flash :notice, :warn
40
+ # should_set_the_flash :notice, :to => 'message'
41
+ # should_set_the_flash :notice, :to => proc{ 'hi ' + users(:first).name }
42
+ # should_set_the_flash(:notice){ 'hi ' + users(:first).name }
43
+ #
44
+ # it { should set_the_flash }
45
+ # it { should set_the_flash.to('message') }
46
+ # it { should set_the_flash(:notice, :warn) }
47
+ # it { should set_the_flash(:notice, :to => 'message') }
48
+ # it { should set_the_flash(:notice, :to => ('hi ' + users(:first).name)) }
49
+ #
50
+ def set_the_flash(*args, &block)
51
+ SetTheFlashMatcher.new(*args, &block).spec(self)
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +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
+
9
+ # Load matchers
10
+ Dir[File.join(dir, 'action_view', 'matchers', '*.rb')].each do |file|
11
+ require file
12
+ end
13
+
14
+ # Iinclude matchers in Spec::Rails
15
+ if defined?(RSpec::Rails)
16
+ Remarkable.include_matchers!(Remarkable::ActionView, RSpec::Rails::ViewExampleGroup)
17
+ end
18
+
@@ -0,0 +1,7 @@
1
+ module Remarkable
2
+ module ActionView
3
+ class Base < Remarkable::Base
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # This will responsable to check which ORM is loaded and include respective
2
+ # matchers.
3
+ #
4
+ if defined?(ActiveRecord::Base)
5
+ unless Remarkable.const_defined?('ActiveRecord')
6
+ begin
7
+ require 'remarkable_activerecord'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ gem 'remarkable_activerecord'
11
+ require 'remarkable_activerecord'
12
+ end
13
+ end
14
+
15
+ # Include Remarkable ActiveRecord matcher in appropriate ExampleGroup
16
+ if defined?(RSpec::Rails)
17
+ Remarkable.include_matchers!(Remarkable::ActiveRecord, RSpec::Rails::ModelExampleGroup)
18
+ end
19
+ end
data/locale/en.yml ADDED
@@ -0,0 +1,110 @@
1
+ en:
2
+ remarkable:
3
+ action_controller:
4
+ responding: "responding to #%{verb} %{action}"
5
+ mime_type: "with %{format}"
6
+
7
+ assign_to:
8
+ description: "assign %{names}"
9
+ expectations:
10
+ assigned_value: "action to assign %{name}, got no assignment"
11
+ is_kind_of: "assign %{name} to be kind of %{with_kind_of}, got a %{assign_class}"
12
+ is_equal_value: "assign %{name} to be equal to %{with}, got %{assign_inspect}"
13
+ optionals:
14
+ with_kind_of:
15
+ positive: "with kind of %{value}"
16
+
17
+ filter_params:
18
+ description: "filter %{params} parameters from log"
19
+ expectations:
20
+ respond_to_filter_params: "controller to respond to filter_parameters (controller is not filtering any parameter)"
21
+ is_filtered: "%{param} to be filtered, got no filtering"
22
+
23
+ redirect_to:
24
+ description: "redirect to %{expected}"
25
+ expectations:
26
+ redirected: "redirect to %{expected}, got no redirect"
27
+ status_matches: "redirect to %{expected} with status %{with}, got status %{status}"
28
+ url_matches: "redirect to %{expected}, got redirect to %{actual}"
29
+ optionals:
30
+ with:
31
+ positive: "with status %{inspect}"
32
+
33
+ render_template:
34
+ description: "render"
35
+ expectations:
36
+ rendered: "template %{template} to be rendered, got no render"
37
+ template_matches: "template %{template} to be rendered, got %{actual_template}"
38
+ layout_matches: "to render with layout %{layout}, got %{actual_layout}"
39
+ status_matches: "to render with status %{with}, got %{actual_status}"
40
+ body_matches: "to render with body %{body}, got %{actual_body}"
41
+ content_type_matches: "to render with content type %{content_type}, got %{actual_content_type}"
42
+ optionals:
43
+ template:
44
+ positive: "template %{inspect}"
45
+ layout:
46
+ positive: "with layout %{inspect}"
47
+ negative: "with no layout"
48
+ with:
49
+ positive: "with %{value}"
50
+ body:
51
+ positive: "with body %{inspect}"
52
+ content_type:
53
+ positive: "with content type %{inspect}"
54
+
55
+ respond_with:
56
+ description: "respond"
57
+ expectations:
58
+ status_matches: "to respond with status %{with}, got %{actual_status}"
59
+ body_matches: "to respond with body %{body}, got %{actual_body}"
60
+ content_type_matches: "to respond with content type %{content_type}, got %{actual_content_type}"
61
+ optionals:
62
+ with:
63
+ positive: "with %{value}"
64
+ body:
65
+ positive: "with body %{inspect}"
66
+ content_type:
67
+ positive: "with content type %{inspect}"
68
+
69
+ route:
70
+ description: "route %{method} %{path} to/from %{options}"
71
+ expectations:
72
+ map_to_path: "to map %{options} to %{method} %{path}, got %{actual}"
73
+ generate_params: "to generate params %{options} from %{method} %{path}, got %{actual}"
74
+
75
+ set_cookies:
76
+ description: "set cookies %{keys}"
77
+ expectations:
78
+ is_not_empty: "any cookie to be set, got %{cookies_inspect}"
79
+ contains_value: "any cookie to be set to %{to}, got %{cookies_inspect}"
80
+ assigned_value: "cookie %{key} to be set, got %{cookies_inspect}"
81
+ is_equal_value: "cookie %{key} to be set to %{to}, got %{cookies_inspect}"
82
+ optionals:
83
+ to:
84
+ positive: "to %{inspect}"
85
+ negative: "to %{inspect}"
86
+
87
+ set_session:
88
+ description: "set session variable %{keys}"
89
+ expectations:
90
+ is_not_empty: "any session variable to be set, got %{session_inspect}"
91
+ contains_value: "any session variable to be set to %{to}, got %{session_inspect}"
92
+ assigned_value: "session variable %{key} to be set, got %{session_inspect}"
93
+ is_equal_value: "session variable %{key} to be set to %{to}, got %{session_inspect}"
94
+ optionals:
95
+ to:
96
+ positive: "to %{inspect}"
97
+ negative: "to %{inspect}"
98
+
99
+ set_the_flash:
100
+ description: "set the flash message %{keys}"
101
+ expectations:
102
+ is_not_empty: "any flash message to be set, got %{flash_inspect}"
103
+ contains_value: "any flash message to be set to %{to}, got %{flash_inspect}"
104
+ assigned_value: "flash message %{key} to be set, got %{flash_inspect}"
105
+ is_equal_value: "flash message %{key} to be set to %{to}, got %{flash_inspect}"
106
+ optionals:
107
+ to:
108
+ positive: "to %{inspect}"
109
+ negative: "to %{inspect}"
110
+
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{remarkable_rails}
8
+ s.version = "4.0.0.alpha4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Carlos Brando", "José Valim"]
12
+ s.date = %q{2010-10-18}
13
+ s.description = %q{Remarkable Rails: collection of matchers and macros with I18n for Rails}
14
+ s.email = ["eduardobrando@gmail.com", "jose.valim@gmail.com"]
15
+ s.extra_rdoc_files = [
16
+ "CHANGELOG",
17
+ "LICENSE",
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ "CHANGELOG",
22
+ "LICENSE",
23
+ "README",
24
+ "lib/remarkable_rails.rb",
25
+ "lib/remarkable_rails/action_controller.rb",
26
+ "lib/remarkable_rails/action_controller/base.rb",
27
+ "lib/remarkable_rails/action_controller/macro_stubs.rb",
28
+ "lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb",
29
+ "lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb",
30
+ "lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb",
31
+ "lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb",
32
+ "lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb",
33
+ "lib/remarkable_rails/action_controller/matchers/route_matcher.rb",
34
+ "lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb",
35
+ "lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb",
36
+ "lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb",
37
+ "lib/remarkable_rails/action_view.rb",
38
+ "lib/remarkable_rails/action_view/base.rb",
39
+ "lib/remarkable_rails/active_orm.rb",
40
+ "locale/en.yml"
41
+ ]
42
+ s.homepage = %q{http://github.com/carlosbrando/remarkable}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubyforge_project = %q{remarkable}
46
+ s.rubygems_version = %q{1.3.7}
47
+ s.summary = %q{Remarkable Rails: collection of matchers and macros with I18n for Rails}
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.alpha11"])
55
+ s.add_runtime_dependency(%q<rspec-rails>, [">= 2.0.0.alpha11"])
56
+ s.add_runtime_dependency(%q<remarkable>, ["~> 4.0.0.alpha4"])
57
+ s.add_runtime_dependency(%q<remarkable_activerecord>, ["~> 4.0.0.alpha4"])
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 2.0.0.alpha11"])
60
+ s.add_dependency(%q<rspec-rails>, [">= 2.0.0.alpha11"])
61
+ s.add_dependency(%q<remarkable>, ["~> 4.0.0.alpha4"])
62
+ s.add_dependency(%q<remarkable_activerecord>, ["~> 4.0.0.alpha4"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rspec>, [">= 2.0.0.alpha11"])
66
+ s.add_dependency(%q<rspec-rails>, [">= 2.0.0.alpha11"])
67
+ s.add_dependency(%q<remarkable>, ["~> 4.0.0.alpha4"])
68
+ s.add_dependency(%q<remarkable_activerecord>, ["~> 4.0.0.alpha4"])
69
+ end
70
+ end
71
+