custom_rspec_matchers 0.0.1
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.
- data/.bundle/config +2 -0
- data/.document +5 -0
- data/.gitignore +27 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +30 -0
- data/custom_rspec_matchers.gemspec +23 -0
- data/lib/custom_rspec_matchers.rb +3 -0
- data/lib/custom_rspec_matchers/matchers/callback_matcher.rb +60 -0
- data/lib/custom_rspec_matchers/matchers/filter_matcher.rb +74 -0
- data/lib/custom_rspec_matchers/matchers/inherit_from_matcher.rb +26 -0
- data/spec/custom_rspec_matchers/controllers/foo_controller_spec.rb +52 -0
- data/spec/custom_rspec_matchers/matchers/callback_mathcer_spec.rb +12 -0
- data/spec/custom_rspec_matchers/matchers/filter_matcher_spec.rb +68 -0
- data/spec/custom_rspec_matchers/matchers/inherit_from_matcher_spec.rb +20 -0
- data/spec/custom_rspec_matchers/models/duck_spec.rb +17 -0
- data/spec/fixtures/filter_matcher_controllers/another_before_filter_controller.rb +3 -0
- data/spec/fixtures/filter_matcher_controllers/foo_controller.rb +18 -0
- data/spec/fixtures/filter_matcher_controllers/no_filters_controller.rb +1 -0
- data/spec/fixtures/filter_matcher_controllers/one_after_filter_controller.rb +3 -0
- data/spec/fixtures/filter_matcher_controllers/one_before_filter_controller.rb +3 -0
- data/spec/fixtures/models/duck.rb +16 -0
- data/spec/spec_helper.rb +12 -0
- metadata +159 -0
data/.bundle/config
ADDED
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
.project
|
23
|
+
.redcar
|
24
|
+
|
25
|
+
pkg/*
|
26
|
+
*.gem
|
27
|
+
.bundle
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@custom
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
custom_rspec_matchers (0.0.1)
|
5
|
+
actionpack (~> 3.0)
|
6
|
+
activemodel (~> 3.0)
|
7
|
+
rake
|
8
|
+
rspec (~> 2.0)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
abstract (1.0.0)
|
14
|
+
actionpack (3.0.1)
|
15
|
+
activemodel (= 3.0.1)
|
16
|
+
activesupport (= 3.0.1)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
erubis (~> 2.6.6)
|
19
|
+
i18n (~> 0.4.1)
|
20
|
+
rack (~> 1.2.1)
|
21
|
+
rack-mount (~> 0.6.12)
|
22
|
+
rack-test (~> 0.5.4)
|
23
|
+
tzinfo (~> 0.3.23)
|
24
|
+
activemodel (3.0.1)
|
25
|
+
activesupport (= 3.0.1)
|
26
|
+
builder (~> 2.1.2)
|
27
|
+
i18n (~> 0.4.1)
|
28
|
+
activesupport (3.0.1)
|
29
|
+
builder (2.1.2)
|
30
|
+
diff-lcs (1.1.2)
|
31
|
+
erubis (2.6.6)
|
32
|
+
abstract (>= 1.0.0)
|
33
|
+
i18n (0.4.1)
|
34
|
+
rack (1.2.1)
|
35
|
+
rack-mount (0.6.13)
|
36
|
+
rack (>= 1.0.0)
|
37
|
+
rack-test (0.5.6)
|
38
|
+
rack (>= 1.0)
|
39
|
+
rake (0.8.7)
|
40
|
+
rspec (2.0.0)
|
41
|
+
rspec-core (= 2.0.0)
|
42
|
+
rspec-expectations (= 2.0.0)
|
43
|
+
rspec-mocks (= 2.0.0)
|
44
|
+
rspec-core (2.0.0)
|
45
|
+
rspec-expectations (2.0.0)
|
46
|
+
diff-lcs (>= 1.1.2)
|
47
|
+
rspec-mocks (2.0.0)
|
48
|
+
rspec-core (= 2.0.0)
|
49
|
+
rspec-expectations (= 2.0.0)
|
50
|
+
tzinfo (0.3.23)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
actionpack (~> 3.0)
|
57
|
+
activemodel (~> 3.0)
|
58
|
+
custom_rspec_matchers!
|
59
|
+
rake
|
60
|
+
rspec (~> 2.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kenny Ortmann
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= custom_rspec_matchers
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Kenny Ortmann. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
desc "Run all examples"
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
|
+
t.rspec_opts = %w[--color]
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :spec do
|
12
|
+
desc "Run all examples using rcov"
|
13
|
+
RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
|
14
|
+
t.rcov = true
|
15
|
+
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
|
16
|
+
t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
21
|
+
|
22
|
+
require 'rake/rdoctask'
|
23
|
+
Rake::RDocTask.new do |rdoc|
|
24
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
25
|
+
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = "test #{version}"
|
28
|
+
rdoc.rdoc_files.include('README*')
|
29
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "custom_rspec_matchers"
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["kenny ortmann", "matt simpson", "amos king"]
|
9
|
+
s.email = ['kenny.ortmann@gmail.com', 'matt.simpson@asolutions.com', 'amos.king@asolutions.com']
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{a few custom rspec matchers we have created to help with testing}
|
12
|
+
s.description = %q{custopm rspec mathcers }
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.add_dependency('rake')
|
19
|
+
s.add_dependency('rspec', '~>2.0')
|
20
|
+
s.add_dependency('actionpack', '~>3.0')
|
21
|
+
s.add_dependency('activemodel', '~>3.0')
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module CustomRspecMatchers
|
2
|
+
module Matchers
|
3
|
+
class CallbackMatcher
|
4
|
+
def initialize(kind, callback_on, method)
|
5
|
+
@kind = kind
|
6
|
+
@callback_on = callback_on
|
7
|
+
@method = method
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(model)
|
11
|
+
@callbacks = model.send("_#{@callback_on}_callbacks").find_all {|cb| cb.kind == @kind && cb.raw_filter == @method}
|
12
|
+
@callbacks.size == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
" has #{@kind}_#{@callback_on} callback on #{@method}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure_message
|
20
|
+
msg = " expected to have #{@kind}_#{@callback_on} callback on #{@method}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def have_after_create_callback(method)
|
25
|
+
CallbackMatcher.new(:after, :create, method)
|
26
|
+
end
|
27
|
+
|
28
|
+
def have_before_create_callback(method)
|
29
|
+
CallbackMatcher.new(:before, :create, method)
|
30
|
+
end
|
31
|
+
|
32
|
+
def have_around_create_callback(method)
|
33
|
+
CallbackMatcher.new(:around, :create, method)
|
34
|
+
end
|
35
|
+
|
36
|
+
def have_after_save_callback(method)
|
37
|
+
CallbackMatcher.new(:after, :save, method)
|
38
|
+
end
|
39
|
+
|
40
|
+
def have_before_save_callback(method)
|
41
|
+
CallbackMatcher.new(:before, :save, method)
|
42
|
+
end
|
43
|
+
|
44
|
+
def have_around_save_callback(method)
|
45
|
+
CallbackMatcher.new(:around, :save, method)
|
46
|
+
end
|
47
|
+
|
48
|
+
def have_after_update_callback(method)
|
49
|
+
CallbackMatcher.new(:after, :update, method)
|
50
|
+
end
|
51
|
+
|
52
|
+
def have_before_update_callback(method)
|
53
|
+
CallbackMatcher.new(:before, :update, method)
|
54
|
+
end
|
55
|
+
|
56
|
+
def have_around_update_callback(method)
|
57
|
+
CallbackMatcher.new(:around, :update, method)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module CustomRspecMatchers
|
2
|
+
module Matchers
|
3
|
+
class FilterMatcher
|
4
|
+
def initialize(filter_type, expected_filter)
|
5
|
+
@filter_type = filter_type
|
6
|
+
@expected_filter = expected_filter
|
7
|
+
@options = {}
|
8
|
+
@failure_message = ''
|
9
|
+
end
|
10
|
+
|
11
|
+
def description
|
12
|
+
"include #{@filter_type.to_s} filter: #{@expected_filter}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def only_on(*only)
|
16
|
+
@options = {:only => only}
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def except_on(*except)
|
21
|
+
@options = {:except => except}
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def matches?(inheriting_instance)
|
26
|
+
filter = inheriting_instance._process_action_callbacks.find_all { |x| x.kind == @filter_type && x.raw_filter == @expected_filter }.first
|
27
|
+
if filter
|
28
|
+
filter_matches(filter)
|
29
|
+
else
|
30
|
+
actual_filters = inheriting_instance._process_action_callbacks.find_all { |x| x.kind == @filter_type }.collect(&:filter)
|
31
|
+
@failure_message = " expected to include #{@filter_type.to_s} filter #{@expected_filter} but not found in #{actual_filters}"
|
32
|
+
end
|
33
|
+
@failure_message.blank?
|
34
|
+
end
|
35
|
+
|
36
|
+
def filter_matches(filter)
|
37
|
+
only_options_difference = options_difference_for_type(filter, :only)
|
38
|
+
except_options_difference = options_difference_for_type(filter, :except)
|
39
|
+
unless only_options_difference.empty? && except_options_difference.empty?
|
40
|
+
@failure_message = " #{@filter_type}_type: #{@expected_filter} was found but these differences exist:\n"
|
41
|
+
unless only_options_difference.empty?
|
42
|
+
@failure_message += " expected only on actions '#{array_text @options[:only]}' but was on '#{array_text filter.options[:only]}'\n"
|
43
|
+
end
|
44
|
+
unless except_options_difference.empty?
|
45
|
+
@failure_message += " expected except on actions '#{array_text @options[:except]}' but was on '#{array_text filter.options[:except]}'\n"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def array_text(array)
|
51
|
+
real_array = ([] << array).flatten.compact
|
52
|
+
real_array.empty? ? '[]' : real_array
|
53
|
+
end
|
54
|
+
|
55
|
+
def options_difference_for_type(filter, option_type)
|
56
|
+
actual_filter_options = ([] << filter.options[option_type]).flatten
|
57
|
+
expected_filter_options = ([] << @options[option_type]).flatten
|
58
|
+
actual_filter_options - expected_filter_options
|
59
|
+
end
|
60
|
+
|
61
|
+
def failure_message
|
62
|
+
@failure_message
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def include_before_filter(expected_filter)
|
67
|
+
FilterMatcher.new :before, expected_filter
|
68
|
+
end
|
69
|
+
|
70
|
+
def include_after_filter(expected_filter)
|
71
|
+
FilterMatcher.new :after, expected_filter
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CustomRspecMatchers
|
2
|
+
module Matchers
|
3
|
+
class InheritFromMatcher
|
4
|
+
def initialize(clazz)
|
5
|
+
@clazz=clazz
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(inheriting_instance)
|
9
|
+
@inheriting_class = inheriting_instance.class.superclass
|
10
|
+
@inheriting_class == @clazz
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
"inherit from #{@clazz}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
" expected to inherit from #{@clazz} but was #{@inheriting_class}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def inherit_from(clazz)
|
23
|
+
InheritFromMatcher.new(clazz)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FooController do
|
4
|
+
describe "before all methods filter" do
|
5
|
+
it { should include_before_filter(:for_all_methods) }
|
6
|
+
end
|
7
|
+
describe "after all methods filter" do
|
8
|
+
it { should include_after_filter(:for_all_methods) }
|
9
|
+
end
|
10
|
+
describe "after_filters only create" do
|
11
|
+
it { should include_after_filter(:after_filter_only_create).only_on(:create) }
|
12
|
+
end
|
13
|
+
describe "after_filters only show" do
|
14
|
+
it { should include_after_filter(:after_filter_only_show).only_on(:show) }
|
15
|
+
end
|
16
|
+
describe "after_filters only show and create" do
|
17
|
+
it { should include_after_filter(:after_filter_only_show_and_create).only_on([:show, :create]) }
|
18
|
+
end
|
19
|
+
describe "after_filters only show and create without array" do
|
20
|
+
it { should include_after_filter(:after_filter_only_show_and_create).only_on(:show, :create) }
|
21
|
+
end
|
22
|
+
describe "after_filters only show and create with params flipped" do
|
23
|
+
it { should include_after_filter(:after_filter_only_show_and_create).only_on([:create, :show]) }
|
24
|
+
end
|
25
|
+
describe "after_filters except create" do
|
26
|
+
it { should include_after_filter(:after_filter_except_create).except_on(:create) }
|
27
|
+
end
|
28
|
+
describe "after_filters except show" do
|
29
|
+
it { should include_after_filter(:after_filter_except_show).except_on(:show) }
|
30
|
+
end
|
31
|
+
describe "after_filters except show and create" do
|
32
|
+
it { should include_after_filter(:after_filter_except_show_and_create).except_on([:show, :create]) }
|
33
|
+
end
|
34
|
+
describe "before_filters only create" do
|
35
|
+
it { should include_before_filter(:before_filter_only_create).only_on(:create) }
|
36
|
+
end
|
37
|
+
describe "before_filters only show" do
|
38
|
+
it { should include_before_filter(:before_filter_only_show).only_on(:show) }
|
39
|
+
end
|
40
|
+
describe "before_filters only show and create" do
|
41
|
+
it { should include_before_filter(:before_filter_only_show_and_create).only_on([:show, :create]) }
|
42
|
+
end
|
43
|
+
describe "before_filters except create" do
|
44
|
+
it { should include_before_filter(:before_filter_except_create).except_on(:create) }
|
45
|
+
end
|
46
|
+
describe "before_filters except show" do
|
47
|
+
it { should include_before_filter(:before_filter_except_show).except_on(:show) }
|
48
|
+
end
|
49
|
+
describe "before_filters except show and create" do
|
50
|
+
it { should include_before_filter(:before_filter_except_show_and_create).except_on([:show, :create]) }
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CallbackMatcher' do
|
4
|
+
before do
|
5
|
+
@type = :save
|
6
|
+
@on = :before
|
7
|
+
@method = :method
|
8
|
+
@to = CustomRspecMatchers::Matchers::CallbackMatcher.new(@on, @type, @method)
|
9
|
+
end
|
10
|
+
it { @to.description.should == " has #{@on}_#{@type} callback on #{@method}"}
|
11
|
+
it { @to.failure_message.should == " expected to have #{@on}_#{@type} callback on #{@method}" }
|
12
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'FilterMatcher' do
|
4
|
+
describe "matcher for a before filter" do
|
5
|
+
before do
|
6
|
+
@filter_under_test = :another_before_filter
|
7
|
+
@matcher = FilterMatcher.new :before, @filter_under_test
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has the correct description" do
|
11
|
+
@matcher.description.should == "include before filter: another_before_filter"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "calling matches? on the matcher with a controller that doesn't have any filters" do
|
15
|
+
before do
|
16
|
+
@test_object = @matcher.matches? NoFiltersController.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false" do
|
20
|
+
@test_object.should == false
|
21
|
+
end
|
22
|
+
it "has the correct failure message" do
|
23
|
+
@matcher.failure_message.should == " expected to include before filter another_before_filter but not found in []"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "calling matches? on the matcher with a controller that doesn't have any before filters" do
|
28
|
+
before do
|
29
|
+
@test_object = @matcher.matches? OneAfterFilterController.new
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns false" do
|
33
|
+
@test_object.should == false
|
34
|
+
end
|
35
|
+
it "has the correct failure message" do
|
36
|
+
@matcher.failure_message.should == " expected to include before filter another_before_filter but not found in []"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "calling matches? on the matcher with a controller that doesn't have the before filter" do
|
41
|
+
before do
|
42
|
+
@test_object = @matcher.matches? OneBeforeFilterController.new
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns false" do
|
46
|
+
@test_object.should == false
|
47
|
+
end
|
48
|
+
it "has the correct failure message" do
|
49
|
+
@matcher.failure_message.should == " expected to include before filter another_before_filter but not found in [:one_before_filter]"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "calling matches? on the matcher with a controller that has only the matching before filter" do
|
54
|
+
before do
|
55
|
+
@controller = AnotherBeforeFilterController.new
|
56
|
+
@test_object = @matcher.matches? @controller
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns false" do
|
60
|
+
@test_object.should == true
|
61
|
+
end
|
62
|
+
it "has the correct failure message" do
|
63
|
+
@matcher.failure_message.should == ""
|
64
|
+
end
|
65
|
+
it { @controller.should include_before_filter(:another_before_filter) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Foo; end
|
4
|
+
class Bar < Foo; end
|
5
|
+
|
6
|
+
describe 'InheritFromMatcher' do
|
7
|
+
before do
|
8
|
+
@bar = Bar.new
|
9
|
+
@to = CustomRspecMatchers::Matchers::InheritFromMatcher.new(Foo)
|
10
|
+
end
|
11
|
+
it { @to.description.should == "inherit from #{Foo}"}
|
12
|
+
it { @to.matches?(Bar.new).should == true }
|
13
|
+
it { @bar.should inherit_from(Foo) }
|
14
|
+
describe 'failure message' do
|
15
|
+
before do
|
16
|
+
@to.matches?(@bar)
|
17
|
+
end
|
18
|
+
it { @to.failure_message.should == " expected to inherit from #{Foo} but was #{@bar.class.superclass}"}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Duck do
|
4
|
+
|
5
|
+
it { should have_after_create_callback(:after_create_callback) }
|
6
|
+
it { should have_around_create_callback(:around_create_callback) }
|
7
|
+
it { should have_before_create_callback(:before_create_callback) }
|
8
|
+
|
9
|
+
it { should have_after_save_callback(:after_save_callback) }
|
10
|
+
it { should have_around_save_callback(:around_save_callback) }
|
11
|
+
it { should have_before_save_callback(:before_save_callback) }
|
12
|
+
|
13
|
+
it { should have_after_update_callback(:after_update_callback) }
|
14
|
+
it { should have_around_update_callback(:around_update_callback) }
|
15
|
+
it { should have_before_update_callback(:before_update_callback) }
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FooController < ActionController::Base
|
2
|
+
before_filter :for_all_methods
|
3
|
+
after_filter :for_all_methods
|
4
|
+
|
5
|
+
after_filter :after_filter_only_create, :only => :create
|
6
|
+
after_filter :after_filter_only_show, :only => :show
|
7
|
+
after_filter :after_filter_only_show_and_create, :only => [:show, :create]
|
8
|
+
after_filter :after_filter_except_show, :except => :show
|
9
|
+
after_filter :after_filter_except_create, :except => :create
|
10
|
+
after_filter :after_filter_except_show_and_create, :except => [:show, :create]
|
11
|
+
|
12
|
+
before_filter :before_filter_only_create, :only => :create
|
13
|
+
before_filter :before_filter_only_show, :only => :show
|
14
|
+
before_filter :before_filter_only_show_and_create, :only => [:show, :create]
|
15
|
+
before_filter :before_filter_except_show, :except => :show
|
16
|
+
before_filter :before_filter_except_create, :except => :create
|
17
|
+
before_filter :before_filter_except_show_and_create, :except => [:show, :create]
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class NoFiltersController < ActionController::Base ; end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Duck
|
2
|
+
extend ActiveModel::Callbacks
|
3
|
+
define_model_callbacks :create, :update, :save
|
4
|
+
after_create :after_create_callback
|
5
|
+
around_create :around_create_callback
|
6
|
+
before_create :before_create_callback
|
7
|
+
|
8
|
+
after_save :after_save_callback
|
9
|
+
around_save :around_save_callback
|
10
|
+
before_save :before_save_callback
|
11
|
+
|
12
|
+
after_update :after_update_callback
|
13
|
+
around_update :around_update_callback
|
14
|
+
before_update :before_update_callback
|
15
|
+
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'custom_rspec_matchers'
|
3
|
+
require 'action_controller'
|
4
|
+
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.include CustomRspecMatchers::Matchers
|
8
|
+
config.include ActionController
|
9
|
+
config.include ActiveModel
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir.glob(File.dirname(__FILE__) + "/fixtures/**/*.rb").each {|f| require f}
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: custom_rspec_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- kenny ortmann
|
13
|
+
- matt simpson
|
14
|
+
- amos king
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-11-11 00:00:00 -06:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rake
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
version: "2.0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: actionpack
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 3
|
59
|
+
- 0
|
60
|
+
version: "3.0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: activemodel
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 3
|
73
|
+
- 0
|
74
|
+
version: "3.0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
description: "custopm rspec mathcers "
|
78
|
+
email:
|
79
|
+
- kenny.ortmann@gmail.com
|
80
|
+
- matt.simpson@asolutions.com
|
81
|
+
- amos.king@asolutions.com
|
82
|
+
executables: []
|
83
|
+
|
84
|
+
extensions: []
|
85
|
+
|
86
|
+
extra_rdoc_files: []
|
87
|
+
|
88
|
+
files:
|
89
|
+
- .bundle/config
|
90
|
+
- .document
|
91
|
+
- .gitignore
|
92
|
+
- .rvmrc
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- custom_rspec_matchers.gemspec
|
99
|
+
- lib/custom_rspec_matchers.rb
|
100
|
+
- lib/custom_rspec_matchers/matchers/callback_matcher.rb
|
101
|
+
- lib/custom_rspec_matchers/matchers/filter_matcher.rb
|
102
|
+
- lib/custom_rspec_matchers/matchers/inherit_from_matcher.rb
|
103
|
+
- spec/custom_rspec_matchers/controllers/foo_controller_spec.rb
|
104
|
+
- spec/custom_rspec_matchers/matchers/callback_mathcer_spec.rb
|
105
|
+
- spec/custom_rspec_matchers/matchers/filter_matcher_spec.rb
|
106
|
+
- spec/custom_rspec_matchers/matchers/inherit_from_matcher_spec.rb
|
107
|
+
- spec/custom_rspec_matchers/models/duck_spec.rb
|
108
|
+
- spec/fixtures/filter_matcher_controllers/another_before_filter_controller.rb
|
109
|
+
- spec/fixtures/filter_matcher_controllers/foo_controller.rb
|
110
|
+
- spec/fixtures/filter_matcher_controllers/no_filters_controller.rb
|
111
|
+
- spec/fixtures/filter_matcher_controllers/one_after_filter_controller.rb
|
112
|
+
- spec/fixtures/filter_matcher_controllers/one_before_filter_controller.rb
|
113
|
+
- spec/fixtures/models/duck.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
has_rdoc: true
|
116
|
+
homepage: ""
|
117
|
+
licenses: []
|
118
|
+
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
requirements: []
|
141
|
+
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 1.3.7
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: a few custom rspec matchers we have created to help with testing
|
147
|
+
test_files:
|
148
|
+
- spec/custom_rspec_matchers/controllers/foo_controller_spec.rb
|
149
|
+
- spec/custom_rspec_matchers/matchers/callback_mathcer_spec.rb
|
150
|
+
- spec/custom_rspec_matchers/matchers/filter_matcher_spec.rb
|
151
|
+
- spec/custom_rspec_matchers/matchers/inherit_from_matcher_spec.rb
|
152
|
+
- spec/custom_rspec_matchers/models/duck_spec.rb
|
153
|
+
- spec/fixtures/filter_matcher_controllers/another_before_filter_controller.rb
|
154
|
+
- spec/fixtures/filter_matcher_controllers/foo_controller.rb
|
155
|
+
- spec/fixtures/filter_matcher_controllers/no_filters_controller.rb
|
156
|
+
- spec/fixtures/filter_matcher_controllers/one_after_filter_controller.rb
|
157
|
+
- spec/fixtures/filter_matcher_controllers/one_before_filter_controller.rb
|
158
|
+
- spec/fixtures/models/duck.rb
|
159
|
+
- spec/spec_helper.rb
|