virtus-rspec 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/lib/virtus-rspec.rb +8 -0
- data/lib/virtus-rspec/version.rb +5 -0
- data/lib/virtus-rspec/virtus_attribute.rb +39 -0
- data/virtus-rspec.gemspec +19 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Cyril Mougel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Virtus::Rspec
|
2
|
+
|
3
|
+
Rspec matcher to virtus gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'virtus-rspec'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install virtus-rspec
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You need include the Virtus::Matchers in your rspec config file
|
22
|
+
|
23
|
+
```
|
24
|
+
RSpec.configure do |configuration|
|
25
|
+
configuration.include Virtus::Matchers
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
You have now access to `have_attribute` matcher.
|
30
|
+
|
31
|
+
```
|
32
|
+
class Post
|
33
|
+
include Virtus
|
34
|
+
attribute :title, String
|
35
|
+
attribute :first_name, String
|
36
|
+
attribute :last_name, String
|
37
|
+
end
|
38
|
+
|
39
|
+
describe Post do
|
40
|
+
it { should have_attribute(:title) }
|
41
|
+
it { should have_attributes(:first_name, :last_name) }
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/virtus-rspec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Virtus
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class HaveAttributeMatcher
|
5
|
+
def initialize(*attrs)
|
6
|
+
@attributes = attrs.collect(&:to_sym)
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(klass)
|
10
|
+
@klass = klass.is_a?(Class) ? klass : klass.class
|
11
|
+
@errors = []
|
12
|
+
@attributes.each do |attr|
|
13
|
+
unless @klass.attribute_set.map(&:name).include?(attr)
|
14
|
+
@errors.push << "no field named #{attr.inspect}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@errors.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_for_should
|
21
|
+
"Expected #{@klass.inspect} to #{description}, got #{@errors.join(',')}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message_for_should_not
|
25
|
+
"Expected #{@klass.inspect} to not #{description}, got #{@klass.inspect} to #{description}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
desc = "have #{@attributes.size > 1 ? 'fields' : 'field'} named #{@attributes.collect(&:inspect).join(',')}"
|
30
|
+
desc << " of type #{@type.inspect}" if @type
|
31
|
+
desc
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def have_attributes(*args)
|
35
|
+
HaveAttributeMatcher.new(*args)
|
36
|
+
end
|
37
|
+
alias :have_attribute :have_attributes
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'virtus-rspec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "virtus-rspec"
|
8
|
+
gem.version = Virtus::Rspec::VERSION
|
9
|
+
gem.authors = ["Cyril Mougel"]
|
10
|
+
gem.email = ["cyril.mougel@gmail.com"]
|
11
|
+
gem.description = %q{Rspec matcher to virtus gem}
|
12
|
+
gem.summary = %q{Rspec matcher to virtus gem}
|
13
|
+
gem.homepage = "https://github.com/shingara/virtus-rspec"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virtus-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cyril Mougel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Rspec matcher to virtus gem
|
15
|
+
email:
|
16
|
+
- cyril.mougel@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/virtus-rspec.rb
|
27
|
+
- lib/virtus-rspec/version.rb
|
28
|
+
- lib/virtus-rspec/virtus_attribute.rb
|
29
|
+
- virtus-rspec.gemspec
|
30
|
+
homepage: https://github.com/shingara/virtus-rspec
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
none: false
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
none: false
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.23
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Rspec matcher to virtus gem
|
54
|
+
test_files: []
|