remockable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +23 -0
- data/lib/remockable/helpers.rb +33 -0
- data/lib/remockable/matchers/validate_acceptance_of.rb +29 -0
- data/lib/remockable/matchers/validate_confirmation_of.rb +29 -0
- data/lib/remockable/matchers/validate_exclusion_of.rb +29 -0
- data/lib/remockable/matchers/validate_format_of.rb +29 -0
- data/lib/remockable/matchers/validate_inclusion_of.rb +29 -0
- data/lib/remockable/matchers/validate_length_of.rb +40 -0
- data/lib/remockable/matchers/validate_numericality_of.rb +29 -0
- data/lib/remockable/matchers/validate_presence_of.rb +29 -0
- data/lib/remockable/matchers.rb +13 -0
- data/lib/remockable.rb +2 -0
- metadata +147 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010-2011 Tyler Hunt
|
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
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Remockable
|
2
|
+
==========
|
3
|
+
|
4
|
+
A collection of RSpec matchers to simplify your web app specs.
|
5
|
+
|
6
|
+
The goal of this project is to provide a modern replacement to the now
|
7
|
+
unmaintained Remarkable project. Remarkable was a great asset when Rails 2.3
|
8
|
+
was current, but now that Rails 3.0 has become mainstream, a gap has been left
|
9
|
+
by still unreleased Remarkable 4.0. In looking at the code for Remarkable to
|
10
|
+
determine the feasibility of continuing work on Remarkable itself, it seems
|
11
|
+
clear that the scope of that project has outgrown its usefulness for most users.
|
12
|
+
It was with this conclusion in mind that Remockable was born. It's an attempt to
|
13
|
+
start with a clean slate but maintain the original goal of Remarkable in spirit.
|
14
|
+
|
15
|
+
|
16
|
+
Matchers
|
17
|
+
========
|
18
|
+
|
19
|
+
In this first release of Remockable, there are matchers for all of the Active
|
20
|
+
Model validations. More are on the way soon.
|
21
|
+
|
22
|
+
|
23
|
+
Copyright (c) 2010-2011 Tyler Hunt, released under the MIT license
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Remockable
|
2
|
+
module Helpers
|
3
|
+
attr_reader :type
|
4
|
+
|
5
|
+
def unsupported_options(keys)
|
6
|
+
@expected.keys.each do |key|
|
7
|
+
if keys.collect(&:to_sym).include?(key.to_sym)
|
8
|
+
raise ArgumentError.new("Unsupported option #{key.inspect}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid_options(keys)
|
14
|
+
@expected.keys.each do |key|
|
15
|
+
unless keys.collect(&:to_sym).include?(key.to_sym)
|
16
|
+
raise ArgumentError.new("Unknown option #{key.inspect}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def validator_for(attribute)
|
22
|
+
subject.class.validators_on(attribute).detect do |validator|
|
23
|
+
validator.kind == type
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_attributes
|
28
|
+
@attributes.inject(true) do |result, attribute|
|
29
|
+
yield validator_for(attribute)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_acceptance_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :acceptance
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(allow_nil accept message on)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_confirmation_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :confirmation
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(message on)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_exclusion_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :exclusion
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(allow_nil allow_blank in message on)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_format_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :format
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(allow_blank allow_nil message on with without)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_inclusion_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :inclusion
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(allow_nil allow_blank in message on)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_length_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :length
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless tokenizer)
|
9
|
+
valid_options %w(allow_blank allow_nil in is maximum message minimum on
|
10
|
+
too_long too_short within wrong_length)
|
11
|
+
|
12
|
+
match do |actual|
|
13
|
+
validate_attributes do |validator|
|
14
|
+
expected = normalize_expected
|
15
|
+
validator && validator.options.slice(*expected.keys) == expected
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def normalize_expected
|
20
|
+
expected.dup.tap do |expected|
|
21
|
+
if within = expected.delete(:within) || expected.delete(:in)
|
22
|
+
expected[:minimum] = within.first
|
23
|
+
expected[:maximum] = within.last
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
failure_message_for_should do |actual|
|
29
|
+
"Expected #{subject.class.name} to #{description}"
|
30
|
+
end
|
31
|
+
|
32
|
+
failure_message_for_should_not do |actual|
|
33
|
+
"Did not expect #{subject.class.name} to #{description}"
|
34
|
+
end
|
35
|
+
|
36
|
+
description do
|
37
|
+
with = " with #{expected.inspect}" if expected.any?
|
38
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_numericality_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :numericality
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(allow_nil equal_to even greater_than greater_than_or_equal_to less_than less_than_or_equal_to message odd on only_integer)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define(:validate_presence_of) do |*attributes|
|
2
|
+
extend Remockable::Helpers
|
3
|
+
|
4
|
+
@type = :presence
|
5
|
+
@expected = attributes.extract_options!
|
6
|
+
@attributes = attributes
|
7
|
+
|
8
|
+
unsupported_options %w(if unless)
|
9
|
+
valid_options %w(message on)
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
validate_attributes do |validator|
|
13
|
+
validator && validator.options.slice(*expected.keys) == expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do |actual|
|
18
|
+
"Expected #{subject.class.name} to #{description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should_not do |actual|
|
22
|
+
"Did not expect #{subject.class.name} to #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
with = " with #{expected.inspect}" if expected.any?
|
27
|
+
"validate #{type} of #{@attributes.to_sentence}#{with}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'active_support/core_ext/array/extract_options'
|
3
|
+
require 'active_support/core_ext/hash/slice'
|
4
|
+
require 'active_support/core_ext/object/try'
|
5
|
+
|
6
|
+
require 'remockable/matchers/validate_acceptance_of'
|
7
|
+
require 'remockable/matchers/validate_confirmation_of'
|
8
|
+
require 'remockable/matchers/validate_exclusion_of'
|
9
|
+
require 'remockable/matchers/validate_format_of'
|
10
|
+
require 'remockable/matchers/validate_inclusion_of'
|
11
|
+
require 'remockable/matchers/validate_length_of'
|
12
|
+
require 'remockable/matchers/validate_numericality_of'
|
13
|
+
require 'remockable/matchers/validate_presence_of'
|
data/lib/remockable.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remockable
|
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
|
+
- Tyler Hunt
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-21 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activemodel
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 3
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 3.0.0
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec-core
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 2
|
60
|
+
- 0
|
61
|
+
version: "2.0"
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: rspec-expectations
|
66
|
+
prerelease: false
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 2
|
74
|
+
- 0
|
75
|
+
version: "2.0"
|
76
|
+
type: :runtime
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec-mocks
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 2
|
88
|
+
- 0
|
89
|
+
version: "2.0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id005
|
92
|
+
description:
|
93
|
+
email:
|
94
|
+
executables: []
|
95
|
+
|
96
|
+
extensions: []
|
97
|
+
|
98
|
+
extra_rdoc_files: []
|
99
|
+
|
100
|
+
files:
|
101
|
+
- README
|
102
|
+
- LICENSE
|
103
|
+
- lib/remockable/helpers.rb
|
104
|
+
- lib/remockable/matchers/validate_acceptance_of.rb
|
105
|
+
- lib/remockable/matchers/validate_confirmation_of.rb
|
106
|
+
- lib/remockable/matchers/validate_exclusion_of.rb
|
107
|
+
- lib/remockable/matchers/validate_format_of.rb
|
108
|
+
- lib/remockable/matchers/validate_inclusion_of.rb
|
109
|
+
- lib/remockable/matchers/validate_length_of.rb
|
110
|
+
- lib/remockable/matchers/validate_numericality_of.rb
|
111
|
+
- lib/remockable/matchers/validate_presence_of.rb
|
112
|
+
- lib/remockable/matchers.rb
|
113
|
+
- lib/remockable.rb
|
114
|
+
has_rdoc: true
|
115
|
+
homepage: http://github.com/tylerhunt/remockable
|
116
|
+
licenses: []
|
117
|
+
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
version: "0"
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
requirements: []
|
140
|
+
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 1.3.7
|
143
|
+
signing_key:
|
144
|
+
specification_version: 3
|
145
|
+
summary: A collection of RSpec matchers to simplify your web app specs.
|
146
|
+
test_files: []
|
147
|
+
|