rspec-am 1.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +23 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/rspec-am/belong_to.rb +22 -0
- data/lib/rspec-am/have_many.rb +22 -0
- data/lib/rspec-am/have_one.rb +22 -0
- data/lib/rspec-am.rb +7 -0
- data/rspec-am.gemspec +67 -0
- data/spec/belong_to_spec.rb +26 -0
- data/spec/fake_data.rb +5 -0
- data/spec/have_many_spec.rb +26 -0
- data/spec/have_one_spec.rb +26 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +115 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Marco
|
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.markdown
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Rspec-am
|
2
|
+
|
3
|
+
Rspec-am is a simple extension of Rspec 2.0 (beta) and provides some useful association matchers like belong_to, have_many and have_one (see usage). It's tested for Rails 3.0 and Rspec 2.
|
4
|
+
|
5
|
+
Gem is developed for rails (version: 3.0.0.beta4), rspec (version: 2.0.0.beta.14) and rspec-rails (version: 2.0.0.beta.17)
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
describe User do
|
10
|
+
|
11
|
+
it { should have_many(:books) }
|
12
|
+
|
13
|
+
it { should have_one(:boss) }
|
14
|
+
|
15
|
+
it { should belong_to(:business) }
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
## Copyright
|
23
|
+
Copyright (c) 2010 SoftwareLab (software-lab.ch). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rspec-am"
|
8
|
+
gem.summary = %Q{This gem provides some simple association matchers if you write tests with Rspec}
|
9
|
+
gem.description = %Q{This gem provides some simple association matchers if you write tests with Rspec}
|
10
|
+
gem.email = "marco@software-lab.ch"
|
11
|
+
gem.homepage = "http://github.com/marcoribi/rspec-am"
|
12
|
+
gem.authors = ["MarcoRibi"]
|
13
|
+
gem.add_development_dependency "rspec"#, '2.0.0.beta.14'
|
14
|
+
gem.add_development_dependency 'rails'
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "rspec-am #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class BelongTo
|
2
|
+
attr_reader :expected_model
|
3
|
+
|
4
|
+
def initialize(expected_model)
|
5
|
+
@expected_model = expected_model
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual_model)
|
9
|
+
@actual_model = actual_model
|
10
|
+
model = actual_model.class if actual_model.is_a? ActiveRecord::Base
|
11
|
+
model.reflect_on_all_associations(:belongs_to).find { |a| a.name == @expected_model } if model
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should
|
15
|
+
"expected a belongs to association from #{@actual_model} to #{@expected_model}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def belong_to(expected_model)
|
21
|
+
BelongTo.new(expected_model)
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class HaveMany
|
2
|
+
attr_reader :expected_model
|
3
|
+
|
4
|
+
def initialize(expected_model)
|
5
|
+
@expected_model = expected_model
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual_model)
|
9
|
+
@actual_model = actual_model
|
10
|
+
model = actual_model.class if actual_model.is_a? ActiveRecord::Base
|
11
|
+
model.reflect_on_all_associations(:has_many).find { |a| a.name == @expected_model } if model
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should
|
15
|
+
"expected a #{@actual_model.class} has many #{@expected_model}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def have_many(expected_model)
|
21
|
+
HaveMany.new(expected_model)
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class HaveOne
|
2
|
+
attr_reader :expected_model
|
3
|
+
|
4
|
+
def initialize(expected_model)
|
5
|
+
@expected_model = expected_model
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual_model)
|
9
|
+
@actual_model = actual_model
|
10
|
+
model = actual_model.class if actual_model.is_a? ActiveRecord::Base
|
11
|
+
model.reflect_on_all_associations(:has_one).find { |a| a.name == @expected_model } if model
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should
|
15
|
+
"expected a #{@actual_model.class} has exactly one #{@expected_model}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def have_one(expected_model)
|
21
|
+
HaveOne.new(expected_model)
|
22
|
+
end
|
data/lib/rspec-am.rb
ADDED
data/rspec-am.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
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{rspec-am}
|
8
|
+
s.version = "1.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["MarcoRibi"]
|
12
|
+
s.date = %q{2010-08-05}
|
13
|
+
s.description = %q{This gem provides some simple association matchers if you write tests with Rspec}
|
14
|
+
s.email = %q{marco@software-lab.ch}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rspec-am.rb",
|
27
|
+
"lib/rspec-am/belong_to.rb",
|
28
|
+
"lib/rspec-am/have_many.rb",
|
29
|
+
"lib/rspec-am/have_one.rb",
|
30
|
+
"rspec-am.gemspec",
|
31
|
+
"spec/belong_to_spec.rb",
|
32
|
+
"spec/fake_data.rb",
|
33
|
+
"spec/have_many_spec.rb",
|
34
|
+
"spec/have_one_spec.rb",
|
35
|
+
"spec/spec.opts",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/marcoribi/rspec-am}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.7}
|
42
|
+
s.summary = %q{This gem provides some simple association matchers if you write tests with Rspec}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/belong_to_spec.rb",
|
45
|
+
"spec/fake_data.rb",
|
46
|
+
"spec/have_many_spec.rb",
|
47
|
+
"spec/have_one_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<rails>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
# A AR-Fakeclass for testing
|
4
|
+
require 'fake_data'
|
5
|
+
|
6
|
+
describe BelongTo do
|
7
|
+
before(:each) do
|
8
|
+
@actual_model = mock('ActualModel')
|
9
|
+
@actual_model.stub!(:class).and_return(Album)
|
10
|
+
@expected_model = :user
|
11
|
+
@belong_to = BelongTo.new(@expected_model)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set expected_model" do
|
15
|
+
@belong_to.expected_model.should be_eql(@expected_model)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match with a AR model and a belongs_to association" do
|
19
|
+
@actual_model.stub!(:is_a?).with(ActiveRecord::Base).and_return(true)
|
20
|
+
@belong_to.matches?(@actual_model).name.should == :user
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not match a none AR model" do
|
24
|
+
@belong_to.matches?(mock('NoneAR')).should be_nil
|
25
|
+
end
|
26
|
+
end
|
data/spec/fake_data.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
# A AR-Fakeclass for testing
|
4
|
+
require 'fake_data'
|
5
|
+
|
6
|
+
describe HaveMany do
|
7
|
+
before(:each) do
|
8
|
+
@actual_model = mock('ActualModel')
|
9
|
+
@actual_model.stub!(:class).and_return(Album)
|
10
|
+
@expected_model = :pictures
|
11
|
+
@have_many = HaveMany.new(@expected_model)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set expected_model" do
|
15
|
+
@have_many.expected_model.should be_eql(@expected_model)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match with a AR model and a belongs_to association" do
|
19
|
+
@actual_model.stub!(:is_a?).with(ActiveRecord::Base).and_return(true)
|
20
|
+
@have_many.matches?(@actual_model).name.should == :pictures
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not match a none AR model" do
|
24
|
+
@have_many.matches?(mock('NoneAR')).should be_nil
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
# A AR-Fakeclass for testing
|
4
|
+
require 'fake_data'
|
5
|
+
|
6
|
+
describe HaveOne do
|
7
|
+
before(:each) do
|
8
|
+
@actual_model = mock('ActualModel')
|
9
|
+
@actual_model.stub!(:class).and_return(Album)
|
10
|
+
@expected_model = :description
|
11
|
+
@have_one = HaveOne.new(@expected_model)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set expected_model" do
|
15
|
+
@have_one.expected_model.should be_eql(@expected_model)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match with a AR model and a belongs_to association" do
|
19
|
+
@actual_model.stub!(:is_a?).with(ActiveRecord::Base).and_return(true)
|
20
|
+
@have_one.matches?(@actual_model).name.should == :description
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not match a none AR model" do
|
24
|
+
@have_one.matches?(mock('NoneAR')).should be_nil
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-am
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- MarcoRibi
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-05 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rails
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: This gem provides some simple association matchers if you write tests with Rspec
|
50
|
+
email: marco@software-lab.ch
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- README.markdown
|
58
|
+
files:
|
59
|
+
- .document
|
60
|
+
- .gitignore
|
61
|
+
- LICENSE
|
62
|
+
- README.markdown
|
63
|
+
- Rakefile
|
64
|
+
- VERSION
|
65
|
+
- lib/rspec-am.rb
|
66
|
+
- lib/rspec-am/belong_to.rb
|
67
|
+
- lib/rspec-am/have_many.rb
|
68
|
+
- lib/rspec-am/have_one.rb
|
69
|
+
- rspec-am.gemspec
|
70
|
+
- spec/belong_to_spec.rb
|
71
|
+
- spec/fake_data.rb
|
72
|
+
- spec/have_many_spec.rb
|
73
|
+
- spec/have_one_spec.rb
|
74
|
+
- spec/spec.opts
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/marcoribi/rspec-am
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.3.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: This gem provides some simple association matchers if you write tests with Rspec
|
110
|
+
test_files:
|
111
|
+
- spec/belong_to_spec.rb
|
112
|
+
- spec/fake_data.rb
|
113
|
+
- spec/have_many_spec.rb
|
114
|
+
- spec/have_one_spec.rb
|
115
|
+
- spec/spec_helper.rb
|