accept_values_for 0.5.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b466c18c67ea0704eacf2be73b449ac00a73c02
4
+ data.tar.gz: 707d2eb9c3d91c587eee0a50ae81730b01769b4e
5
+ SHA512:
6
+ metadata.gz: 233db06ae71d2d69994af4af2be46760dd463becdb0655353c3e5f77fb338435054def203e61325d18c768266402a773dd5661a2d01b44309407190337450410
7
+ data.tar.gz: 805f71fc9be9b172d9e0b8e85c68962860b6e47e65a6487de0340e880bbeec186dd783ec4778e4c63f9623a05baed383b70e140b82a2e33f93b7b7e86b713d0b
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ gemfiles/*.lock
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ spec.log
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.travis.yml CHANGED
@@ -1,24 +1,24 @@
1
1
  language: ruby
2
- env:
3
- - "RAILS_VERSION=3.0.0"
4
- - "RAILS_VERSION=3.1.0"
5
- - "RAILS_VERSION=3.2.0"
6
- - "RAILS_VERSION=4.0.0"
7
2
  rvm:
8
3
  - 1.8.7
9
4
  - 1.9.2
10
5
  - 1.9.3
11
6
  - 2.0.0
7
+ - 2.1.0
8
+ gemfile:
9
+ - gemfiles/activemodel_3_0.gemfile
10
+ - gemfiles/activemodel_3_1.gemfile
11
+ - gemfiles/activemodel_3_2.gemfile
12
+ - gemfiles/activemodel_4_0.gemfile
12
13
  matrix:
13
14
  exclude:
15
+ - gemfile: gemfiles/activemodel_4_0.gemfile
16
+ rvm: 1.8.7
17
+ - gemfile: gemfiles/activemodel_4_0.gemfile
18
+ rvm: 1.9.2
19
+ allow_failures:
14
20
  - rvm: 1.8.7
15
- env: "RAILS_VERSION=4.0.0"
16
21
  - rvm: 1.9.2
17
- env: "RAILS_VERSION=4.0.0"
18
- notifications:
19
- email:
20
- - agresso@gmail.com
21
22
  branches:
22
23
  only:
23
24
  - master
24
-
data/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # 0.6.0 / Unreleased
2
+
3
+ * [ENHANCEMENT] Deprecate Rubies 1.8.7 and 1.9.2
4
+ * [ENHANCEMENT] Remove `discover` matcher
5
+ * [BUGFIX] Open dependency requirements to allow installation alongside Rails 4
6
+ * [ENHANCEMENT] Replace Jeweler with Bundler
7
+
8
+ # 0.5.1 / 2013-10-20
9
+
10
+ * [ENHANCEMENT] Refactor matcher messaging
11
+ * [ENHANCEMENT] Deprecate `discover` matcher in favor of `include`
12
+
13
+ # 0.4.3 / 2011-03-29
14
+
15
+ * [BUGFIX] Revert values set during validation testing
16
+
17
+ # 0.4.2 / 2011-03-15
18
+
19
+ * [BUGFIX] Change error access from `#on` to `#[]`
20
+
21
+ # 0.4.1 / 2011-02-24
22
+
23
+ * [FEATURE] Add wider Active Model compatibility
24
+
25
+ # 0.3.1 / 2010-09-08
26
+
27
+ * [FEATURE] Add Rails 3 compatibility
28
+
29
+ # 0.3.0 / 2010-07-11
30
+
31
+ * [FEATURE] Add `discover` matcher
32
+
33
+ # 0.2.1 / 2010-06-28
34
+
35
+ * [FEATURE] Add support for negative matching
36
+
37
+ # 0.2.0 / 2010-05-13
38
+
39
+ * [FEATURE] Fail only if the validation in question fails
40
+ * [BUGFIX] Add `activerecord` and `rspec` runtime dependencies
41
+
42
+ # 0.1.1 / 2010-05-04
43
+
44
+ * [BUGFIX] Fix non-attribute validation testing
45
+
46
+ # 0.1.0 / 2010-05-04
47
+
48
+ * [FEATURE] Enable testing methods as well as attributes
49
+
50
+ # 0.0.1 / 2010-05-03
51
+
52
+ * Initial release
data/Gemfile CHANGED
@@ -1,22 +1,9 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- rails_version = ENV['RAILS_VERSION'] || 'default'
3
+ gemspec
4
4
 
5
- rails = case rails_version
6
- when 'master'
7
- { :github => 'rails/rails'}
8
- when "default"
9
- '~> 3.2.0'
10
- else
11
- "~> #{rails_version}"
12
- end
13
-
14
- gem 'activemodel', rails
15
-
16
- group :development, :test do
17
- gem 'rspec', '>=0'
18
- gem 'rails', rails
19
- gem 'rspec-rails', '>=2.0.0'
20
- gem 'jeweler'
21
- gem 'sqlite3-ruby'
5
+ group :test do
6
+ gem "activerecord", "~> 4.0", :require => "active_record"
7
+ gem "rspec", "~> 2.14"
8
+ gem "sqlite3", "~> 1.3"
22
9
  end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Bogdan Gusiev
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,46 @@
1
+ # AcceptValuesFor
2
+
3
+ Writing specs for complex validations is annoying. AcceptValuesFor makes it easy
4
+ to test your validations with real world values, asserting which values should
5
+ be accepted by your model and which should not.
6
+
7
+ Read the [original blog post](http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/).
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/accept_values_for.png)](http://badge.fury.io/rb/accept_values_for)
10
+ [![Build Status](https://travis-ci.org/bogdan/accept_values_for.png?branch=master)](https://travis-ci.org/bogdan/accept_values_for)
11
+ [![Code Climate](https://codeclimate.com/github/bogdan/accept_values_for.png)](https://codeclimate.com/github/bogdan/accept_values_for)
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ describe User do
17
+ describe "validation"
18
+ subject(:user) { User.new }
19
+
20
+ it { should accept_values_for(:email, "john@example.com", "jane@example.org") }
21
+ it { should_not accept_values_for(:email, nil, " ", "john", "john@example") }
22
+ end
23
+ end
24
+ ```
25
+
26
+ ## Dependencies
27
+
28
+ * Active Model (3 or 4)
29
+ * RSpec (2)
30
+
31
+ ## Installation
32
+
33
+ ### Gemfile
34
+
35
+ ```ruby
36
+ group :test do
37
+ gem "accept_values_for"
38
+ end
39
+ ```
40
+
41
+ ## Self-Promotion
42
+
43
+ Like AcceptValuesFor?
44
+
45
+ Watch the repository on [GitHub](https://github.com/bogdan/accept_values_for)
46
+ and read [my blog](http://gusiev.com).
data/Rakefile CHANGED
@@ -1,32 +1,7 @@
1
- require 'rubygems'
2
- require "bundler"
3
- Bundler.setup
1
+ require "rubygems"
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
4
 
5
- require 'rake'
6
- require 'rspec/core/rake_task'
7
-
8
- RSpec::Core::RakeTask.new(:spec) do |spec|
9
- end
10
-
11
- begin
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gemspec|
14
- gemspec.name = "accept_values_for"
15
- gemspec.summary = "In order to test a complex validation for ActiveRecord models Implemented accept_values_for custom rspec matcher"
16
- gemspec.description = <<-EOI
17
- Rspec: When you have a complex validation(e.g. regexp or custom method) on ActiveRecord model
18
- you have to write annoying easy specs on which values should be accepted by your validation method and which should not.
19
- accepts_values_for rspec matcher simplify the code. See example for more information.
20
- EOI
21
- gemspec.email = "agresso@gmail.com"
22
- gemspec.homepage = "http://github.com/bogdan/accept_values_for"
23
- gemspec.authors = ["Bogdan Gusiev"]
24
- #gemspec.add_dependency "activerecord"
25
- #gemspec.add_dependency "rspec"
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
- rescue LoadError
29
- puts "Jeweler not available. Install it with: [sudo] gem install jeweler"
30
- end
5
+ RSpec::Core::RakeTask.new(:spec)
31
6
 
32
7
  task :default => :spec
@@ -1,65 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = "accept_values_for"
8
- s.version = "0.5.1"
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "accept_values_for"
5
+ spec.version = "0.7.0"
9
6
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Bogdan Gusiev"]
12
- s.date = "2013-10-20"
13
- s.description = "Rspec: When you have a complex validation(e.g. regexp or custom method) on ActiveRecord model\nyou have to write annoying easy specs on which values should be accepted by your validation method and which should not.\naccepts_values_for rspec matcher simplify the code. See example for more information.\n"
14
- s.email = "agresso@gmail.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE"
17
- ]
18
- s.files = [
19
- ".travis.yml",
20
- "Changelog.textile",
21
- "Gemfile",
22
- "LICENSE",
23
- "Rakefile",
24
- "Readme.md",
25
- "VERSION",
26
- "accept_values_for.gemspec",
27
- "lib/accept_values_for.rb",
28
- "lib/discover.rb",
29
- "spec/accept_values_for_spec.rb",
30
- "spec/discover_spec.rb",
31
- "spec/spec_helper.rb"
32
- ]
33
- s.homepage = "http://github.com/bogdan/accept_values_for"
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = "1.8.24"
36
- s.summary = "In order to test a complex validation for ActiveRecord models Implemented accept_values_for custom rspec matcher"
7
+ spec.author = "Bogdan Gusiev"
8
+ spec.email = "agresso@gmail.com"
9
+ spec.homepage = "https://github.com/bogdan/accept_values_for"
10
+ spec.license = "MIT"
11
+ spec.summary = "Test complex Active Record validations with RSpec"
12
+ spec.description = <<-DESC.gsub(/(^\s+|\n)/, "")
13
+ Writing specs for complex validations is annoying. AcceptValuesFor makes it
14
+ easy to test your validations with real world values, asserting which values
15
+ should be accepted by your model and which should not.
16
+ DESC
37
17
 
38
- if s.respond_to? :specification_version then
39
- s.specification_version = 3
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.test_files = spec.files.grep(/^spec/)
40
20
 
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<activemodel>, ["~> 3.2.0"])
43
- s.add_development_dependency(%q<rspec>, [">= 0"])
44
- s.add_development_dependency(%q<rails>, ["~> 3.2.0"])
45
- s.add_development_dependency(%q<rspec-rails>, [">= 2.0.0"])
46
- s.add_development_dependency(%q<jeweler>, [">= 0"])
47
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
48
- else
49
- s.add_dependency(%q<activemodel>, ["~> 3.2.0"])
50
- s.add_dependency(%q<rspec>, [">= 0"])
51
- s.add_dependency(%q<rails>, ["~> 3.2.0"])
52
- s.add_dependency(%q<rspec-rails>, [">= 2.0.0"])
53
- s.add_dependency(%q<jeweler>, [">= 0"])
54
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
55
- end
56
- else
57
- s.add_dependency(%q<activemodel>, ["~> 3.2.0"])
58
- s.add_dependency(%q<rspec>, [">= 0"])
59
- s.add_dependency(%q<rails>, ["~> 3.2.0"])
60
- s.add_dependency(%q<rspec-rails>, [">= 2.0.0"])
61
- s.add_dependency(%q<jeweler>, [">= 0"])
62
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
63
- end
64
- end
21
+ spec.add_dependency "activemodel", ">= 3", "< 5"
22
+ spec.add_dependency "rspec", "~> 2.0"
65
23
 
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake", "~> 10.1"
26
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => ".."
4
+
5
+ gem "activemodel", "~> 3.0.0"
6
+
7
+ group :test do
8
+ gem "activerecord", "~> 3.0.0", :require => "active_record"
9
+ gem "rspec", "~> 2.14"
10
+ gem "sqlite3-ruby", "~> 1.3"
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => ".."
4
+
5
+ gem "activemodel", "~> 3.1.0"
6
+
7
+ group :test do
8
+ gem "activerecord", "~> 3.1.0", :require => "active_record"
9
+ gem "rspec", "~> 2.14"
10
+ gem "sqlite3-ruby", "~> 1.3"
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => ".."
4
+
5
+ gem "activemodel", "~> 3.2.0"
6
+
7
+ group :test do
8
+ gem "activerecord", "~> 3.2.0", :require => "active_record"
9
+ gem "rspec", "~> 2.14"
10
+ gem "sqlite3-ruby", "~> 1.3"
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => ".."
4
+
5
+ gem "activemodel", "~> 4.0.0"
6
+
7
+ group :test do
8
+ gem "activerecord", "~> 4.0.0", :require => "active_record"
9
+ gem "rspec", "~> 2.14"
10
+ gem "sqlite3-ruby", "~> 1.3"
11
+ end
@@ -1,92 +1,8 @@
1
- if defined?(ActiveModel)
2
-
3
- # In order to spec a complex validation for ActiveRecord models
4
- # Implemented accept_values_for custom matcher
5
- #
6
- # :call-seq:
7
- # model.should accept_values_for(attribute, value1, value2 ...)
8
- # model.should_not accept_values_for(attribute, value1, value2 ...)
9
- #
10
- # model should be an instance of ActiveRecord::Base
11
- # attribute should be the model attribute name
12
- #
13
- # Use this if you want to check that model should not have errors
14
- # on specified attribute with the given values
15
- #
16
- # == Examples
17
- #
18
- # user.should accept_values_for(:email, "john@example.com", "lambda@gusiev.com")
19
- # user.should_not accept_values_for(:email, "invalid", nil, "a@b", "john@.com")
20
- #
21
- #
22
- def accept_values_for(attribute, *values)
23
- AcceptValuesFor.new(attribute, *values)
24
- end
25
-
26
-
27
- end
28
-
29
- class AcceptValuesFor #:nodoc:
30
-
31
- def initialize(attribute, *values)
32
- @attribute = attribute
33
- @values = values
34
- @failed_values = {}
35
- end
36
-
37
- def matches?(model)
38
- base_matches?(model) do |value|
39
- unless model.errors[@attribute].to_a.empty?
40
- @failed_values[value] = Array(model.errors[@attribute]).join(", ")
41
- end
42
- end
43
- end
44
-
45
- def does_not_match?(model)
46
- base_matches?(model) do |value|
47
- if model.errors[@attribute].to_a.empty?
48
- @failed_values[value] = nil
49
- end
50
- end
51
- end
1
+ require "rspec"
52
2
 
53
- def failure_message_for_should
54
- result = "expected #{@model.inspect} to accept values #{formatted_failed_values} for #{@attribute.inspect}, but it was not\n"
55
- @failed_values.keys.sort.each do |key|
56
- result << "\nValue: #{key}\tErrors: #{@attribute} #{@failed_values[key]}"
57
- end
58
- result
59
- end
3
+ require "accept_values_for/helpers"
4
+ require "accept_values_for/matcher"
60
5
 
61
- def failure_message_for_should_not
62
- "expected #{@model.inspect} to not accept values #{formatted_failed_values} for #{@attribute.inspect} attribute, but was"
63
- end
64
-
65
- def description
66
- "accept values #{@values.map(&:inspect).join(', ')} for #{@attribute.inspect} attribute"
67
- end
68
-
69
- private
70
- def base_matches?(model)
71
- @model = model
72
- !has_validations_module?(model) and return false
73
- old_value = @model.send(@attribute)
74
- @values.each do |value|
75
- model.send("#@attribute=", value)
76
- model.valid?
77
- yield(value) if @model.respond_to?(:errors) && @model.errors.is_a?(ActiveModel::Errors)
78
- end
79
- return @failed_values.empty?
80
- ensure
81
- @model.send("#@attribute=", old_value) if defined?(old_value)
82
- end
83
-
84
- def has_validations_module?(model)
85
- model.class.included_modules.include?(ActiveModel::Validations)
86
- end
87
-
88
- def formatted_failed_values
89
- @failed_values.keys.sort.map(&:inspect).join(", ")
90
- end
6
+ RSpec.configure do |config|
7
+ config.include(AcceptValuesFor::Helpers)
91
8
  end
92
-
@@ -0,0 +1,7 @@
1
+ module AcceptValuesFor
2
+ module Helpers
3
+ def accept_values_for(*args)
4
+ Matcher.new(*args)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,66 @@
1
+ require "active_model"
2
+
3
+ module AcceptValuesFor
4
+ class Matcher
5
+ def initialize(attribute, *values)
6
+ @attribute = attribute
7
+ @values = values
8
+ @failed_values = {}
9
+ end
10
+
11
+ def matches?(model)
12
+ base_matches?(model) do |value|
13
+ unless model.errors[@attribute].to_a.empty?
14
+ @failed_values[value] = Array(model.errors[@attribute]).join(", ")
15
+ end
16
+ end
17
+ end
18
+
19
+ def does_not_match?(model)
20
+ base_matches?(model) do |value|
21
+ if model.errors[@attribute].to_a.empty?
22
+ @failed_values[value] = nil
23
+ end
24
+ end
25
+ end
26
+
27
+ def failure_message_for_should
28
+ result = "expected #{@model.inspect} to accept values #{formatted_failed_values} for #{@attribute.inspect}, but it was not\n"
29
+ @failed_values.keys.sort.each do |key|
30
+ result << "\nValue: #{key}\tErrors: #{@attribute} #{@failed_values[key]}"
31
+ end
32
+ result
33
+ end
34
+
35
+ def failure_message_for_should_not
36
+ "expected #{@model.inspect} to not accept values #{formatted_failed_values} for #{@attribute.inspect} attribute, but was"
37
+ end
38
+
39
+ def description
40
+ "accept values #{@values.map(&:inspect).join(', ')} for #{@attribute.inspect} attribute"
41
+ end
42
+
43
+ private
44
+ def base_matches?(model)
45
+ @model = model
46
+ !has_validations_module?(model) and return false
47
+ old_value = @model.send(@attribute)
48
+ @values.each do |value|
49
+ model.send("#@attribute=", value)
50
+ model.valid?
51
+ yield(value) if @model.respond_to?(:errors) && @model.errors.is_a?(ActiveModel::Errors)
52
+ end
53
+ return @failed_values.empty?
54
+ ensure
55
+ @model.send("#@attribute=", old_value) if defined?(old_value)
56
+ end
57
+
58
+ def has_validations_module?(model)
59
+ model.class.included_modules.include?(ActiveModel::Validations)
60
+ end
61
+
62
+ def formatted_failed_values
63
+ @failed_values.keys.sort.map(&:inspect).join(", ")
64
+ end
65
+ end
66
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,54 +1,43 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
- require 'sqlite3'
3
- require 'rspec'
4
- require 'rspec/autorun'
5
- require 'active_record/railtie'
1
+ require "accept_values_for"
6
2
 
7
- $LOAD_PATH << "."
8
- require 'lib/accept_values_for'
9
- require 'lib/discover'
3
+ require "bundler"
4
+ Bundler.require(:test)
10
5
 
11
- require 'rspec/rails'
12
-
13
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
14
- ActiveRecord::Base.configurations = true
15
-
16
- File.open('spec.log', "w").close
17
- ActiveRecord::Base.logger = Logger.new('spec.log')
18
-
19
- ActiveRecord::Schema.verbose = false
20
- ActiveRecord::Schema.define(:version => 1) do
21
-
22
- create_table :people do |t|
23
- t.string :gender
24
- t.integer :group_id
25
- t.string :name
26
- end
27
-
28
- create_table :groups do |t|
29
- t.string :name
6
+ RSpec.configure do |config|
7
+ config.before(:suite) do
8
+ ActiveRecord::Base.establish_connection(
9
+ :adapter => "sqlite3",
10
+ :database => ":memory:"
11
+ )
12
+
13
+ ActiveRecord::Schema.verbose = false
14
+ ActiveRecord::Schema.define(:version => 1) do
15
+ create_table :groups do |t|
16
+ t.string :name
17
+ end
18
+
19
+ create_table :people do |t|
20
+ t.integer :group_id
21
+ t.string :gender
22
+ t.string :name
23
+ end
24
+ end
30
25
  end
31
- end
32
26
 
33
- RSpec.configure do |config|
34
- config.use_transactional_fixtures = true
35
- config.before(:each) do
27
+ config.before do
36
28
  class ::Group < ActiveRecord::Base
37
29
  has_many :people
38
-
39
- scope :by_char, lambda { |char|
40
- where('name like ?', char + '%').order('name')
41
- }
42
30
  end
43
31
 
44
32
  class ::Person < ActiveRecord::Base
45
33
  belongs_to :group
46
- validates_inclusion_of :gender, :in => ["MALE", "FEMALE"]
34
+
47
35
  validates_presence_of :group
36
+ validates_inclusion_of :gender, :in => ["MALE", "FEMALE"]
48
37
  end
49
38
  end
50
39
 
51
- config.after(:each) do
40
+ config.after do
52
41
  Object.send(:remove_const, :Person)
53
42
  Object.send(:remove_const, :Group)
54
43
  end
metadata CHANGED
@@ -1,166 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accept_values_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bogdan Gusiev
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-20 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activemodel
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ - - <
20
21
  - !ruby/object:Gem::Version
21
- version: 3.2.0
22
+ version: '5'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ~>
27
+ - - '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 3.2.0
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
29
+ version: '3'
30
+ - - <
36
31
  - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
32
+ version: '5'
46
33
  - !ruby/object:Gem::Dependency
47
- name: rails
34
+ name: rspec
48
35
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
36
  requirements:
51
37
  - - ~>
52
38
  - !ruby/object:Gem::Version
53
- version: 3.2.0
54
- type: :development
39
+ version: '2.0'
40
+ type: :runtime
55
41
  prerelease: false
56
42
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
43
  requirements:
59
44
  - - ~>
60
45
  - !ruby/object:Gem::Version
61
- version: 3.2.0
46
+ version: '2.0'
62
47
  - !ruby/object:Gem::Dependency
63
- name: rspec-rails
48
+ name: bundler
64
49
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
50
  requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: 2.0.0
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: 2.0.0
78
- - !ruby/object:Gem::Dependency
79
- name: jeweler
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
51
+ - - ~>
84
52
  - !ruby/object:Gem::Version
85
- version: '0'
53
+ version: '1.5'
86
54
  type: :development
87
55
  prerelease: false
88
56
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
57
  requirements:
91
- - - ! '>='
58
+ - - ~>
92
59
  - !ruby/object:Gem::Version
93
- version: '0'
60
+ version: '1.5'
94
61
  - !ruby/object:Gem::Dependency
95
- name: sqlite3-ruby
62
+ name: rake
96
63
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
64
  requirements:
99
- - - ! '>='
65
+ - - ~>
100
66
  - !ruby/object:Gem::Version
101
- version: '0'
67
+ version: '10.1'
102
68
  type: :development
103
69
  prerelease: false
104
70
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
71
  requirements:
107
- - - ! '>='
72
+ - - ~>
108
73
  - !ruby/object:Gem::Version
109
- version: '0'
110
- description: ! 'Rspec: When you have a complex validation(e.g. regexp or custom method)
111
- on ActiveRecord model
112
-
113
- you have to write annoying easy specs on which values should be accepted by your
114
- validation method and which should not.
115
-
116
- accepts_values_for rspec matcher simplify the code. See example for more information.
117
-
118
- '
74
+ version: '10.1'
75
+ description: Writing specs for complex validations is annoying. AcceptValuesFor makes
76
+ iteasy to test your validations with real world values, asserting which valuesshould
77
+ be accepted by your model and which should not.
119
78
  email: agresso@gmail.com
120
79
  executables: []
121
80
  extensions: []
122
- extra_rdoc_files:
123
- - LICENSE
81
+ extra_rdoc_files: []
124
82
  files:
83
+ - .gitignore
125
84
  - .travis.yml
126
- - Changelog.textile
85
+ - CHANGELOG.md
127
86
  - Gemfile
128
- - LICENSE
87
+ - LICENSE.txt
88
+ - README.md
129
89
  - Rakefile
130
- - Readme.md
131
- - VERSION
132
90
  - accept_values_for.gemspec
91
+ - gemfiles/activemodel_3_0.gemfile
92
+ - gemfiles/activemodel_3_1.gemfile
93
+ - gemfiles/activemodel_3_2.gemfile
94
+ - gemfiles/activemodel_4_0.gemfile
133
95
  - lib/accept_values_for.rb
134
- - lib/discover.rb
96
+ - lib/accept_values_for/helpers.rb
97
+ - lib/accept_values_for/matcher.rb
135
98
  - spec/accept_values_for_spec.rb
136
- - spec/discover_spec.rb
137
99
  - spec/spec_helper.rb
138
- homepage: http://github.com/bogdan/accept_values_for
139
- licenses: []
100
+ homepage: https://github.com/bogdan/accept_values_for
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
140
104
  post_install_message:
141
105
  rdoc_options: []
142
106
  require_paths:
143
107
  - lib
144
108
  required_ruby_version: !ruby/object:Gem::Requirement
145
- none: false
146
109
  requirements:
147
- - - ! '>='
110
+ - - '>='
148
111
  - !ruby/object:Gem::Version
149
112
  version: '0'
150
- segments:
151
- - 0
152
- hash: 2380830959568046608
153
113
  required_rubygems_version: !ruby/object:Gem::Requirement
154
- none: false
155
114
  requirements:
156
- - - ! '>='
115
+ - - '>='
157
116
  - !ruby/object:Gem::Version
158
117
  version: '0'
159
118
  requirements: []
160
119
  rubyforge_project:
161
- rubygems_version: 1.8.24
120
+ rubygems_version: 2.2.2
162
121
  signing_key:
163
- specification_version: 3
164
- summary: In order to test a complex validation for ActiveRecord models Implemented
165
- accept_values_for custom rspec matcher
166
- test_files: []
122
+ specification_version: 4
123
+ summary: Test complex Active Record validations with RSpec
124
+ test_files:
125
+ - spec/accept_values_for_spec.rb
126
+ - spec/spec_helper.rb
data/Changelog.textile DELETED
@@ -1,12 +0,0 @@
1
- h3. 0.4.2
2
-
3
- * Make suitable to use with any ORM based on ActiveModel::Validations
4
-
5
- h3. 0.4.0
6
-
7
- * Migrated to ActiveRecord 3.0
8
- * Migrated to Rspec 2.0
9
-
10
- h3. 0.3.0
11
-
12
- * add 'discover' matcher to test named scopes
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2012 Bogdan Gusiev
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is furnished
8
- to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- SOFTWARE.
data/Readme.md DELETED
@@ -1,49 +0,0 @@
1
- # Accept values for
2
-
3
- ## Description
4
-
5
- This gem provides an rspec matcher that helps you to test ActiveModel validation.
6
-
7
- *NOTE:* `discover` matcher that was previously here was extracted to its own gem
8
-
9
- ## Usage
10
-
11
- [RSpec matcher to test the validation](http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/)
12
-
13
- ``` ruby
14
- describe User do
15
-
16
- subject { User.new(@valid_attributes)}
17
-
18
- it { should accept_values_for(:email, "john@example.com", "lambda@gusiev.com") }
19
- it { should_not accept_values_for(:email, "invalid", nil, "a@b", "john@.com") }
20
- end
21
- ```
22
-
23
- You can specify which values should be accepted by model as valid and which values should not be accepted as invalid.
24
-
25
-
26
- ## Dependencies
27
-
28
- * ActiveModel
29
- * Rspec
30
-
31
- ## Install
32
-
33
-
34
- ### Gemfile
35
-
36
- ``` ruby
37
- group :test do
38
- gem 'accept_values_for'
39
- end
40
- ```
41
-
42
-
43
- ## Self-Promotion
44
-
45
- Like accept\_values\_for?
46
-
47
- Follow the repository on [GitHub](https://github.com/bogdan/accept_values_for).
48
-
49
- Read [author blog](http://gusiev.com).
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.1
data/lib/discover.rb DELETED
@@ -1,7 +0,0 @@
1
- if defined?(ActiveRecord) && !respond_to?(:discover)
2
- def discover(*objects) #:nodoc:
3
- include(*objects)
4
- end
5
- warn "#discover matcher was removed from accept_values_for. Use gem discover instead"
6
- end
7
-
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Discover" do
4
-
5
-
6
- let(:named_scope) {
7
- Group.by_char("j")
8
- }
9
- let(:java) { Group.create!(:name => "java") }
10
- let(:json) { Group.create!(:name => "json") }
11
- let(:jruby) { Group.create!(:name => "jruby") }
12
- let(:ruby) { Group.create!(:name => "ruby")}
13
- let(:python) { Group.create!(:name => "python")}
14
-
15
-
16
- describe "api" do
17
- subject {
18
- named_scope
19
- }
20
-
21
- it { should discover(java) }
22
-
23
- it { should discover(json, java, jruby) }
24
-
25
-
26
-
27
- it { should_not discover(ruby) }
28
- it { should_not discover(ruby, python) }
29
-
30
- end
31
-
32
-
33
- end