rspec_attribute_matchers 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rspec_attribute_matchers.rb +34 -0
- metadata +45 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module RSpecAttributeMatchers
|
2
|
+
def properties_to_sentence(hash)
|
3
|
+
" of " + hash.map { |key, value| "#{key} #{value}" }.to_sentence
|
4
|
+
end
|
5
|
+
|
6
|
+
RSpec::Matchers.define :have_attribute do |attr|
|
7
|
+
attr = attr.to_s
|
8
|
+
|
9
|
+
chain :with do |extras|
|
10
|
+
@extras = extras
|
11
|
+
end
|
12
|
+
|
13
|
+
match do |target|
|
14
|
+
result = target.attributes.include? attr
|
15
|
+
|
16
|
+
if result && @extras
|
17
|
+
properties = target.class.columns_hash[attr]
|
18
|
+
@extras.each_pair do |property, value|
|
19
|
+
result = false && break unless properties.send(property) == value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
failure_message_for_should do |target|
|
27
|
+
"Expected #{target.class} to have an attribute '#{attr}'#{properties_to_sentence @extras}."
|
28
|
+
end
|
29
|
+
|
30
|
+
description do
|
31
|
+
"have an attribute '#{attr}'#{properties_to_sentence @extras}."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_attribute_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sujoy Gupta
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: sujoyg@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/rspec_attribute_matchers.rb
|
21
|
+
homepage: http://github.com/sujoyg/rspec_attribute_matchers
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.24
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: RSpec matchers for writing specs for activemodel attributes.
|
45
|
+
test_files: []
|