ubazu 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.2)
19
+ rcov
20
+ shoulda
data/README ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = ubazu
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ubazu
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Silviu Rosu. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "ubazu"
16
+ gem.homepage = "http://github.com/silviurosu/ubazu"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Practical utilities to use in projects}
19
+ gem.description = %Q{A collections of utilities to be used in different projects: ..., rspec expectations, etc.}
20
+ gem.email = "silviu.rosu@gmail.com"
21
+ gem.authors = ["Silviu Rosu"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : "0.1.0"
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ubazu #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/lib/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Silviu Rosu
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.
@@ -0,0 +1,36 @@
1
+ module Ubazu
2
+ module Rspec # :nodoc:
3
+ module Matchers
4
+ module ActiveRecord # :nodoc:
5
+ module Helpers
6
+ def pretty_error_messages(obj) # :nodoc:
7
+ obj.errors.map do |a, m|
8
+ msg = "#{a} #{m}"
9
+ msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base
10
+ end
11
+ end
12
+
13
+ # Helper method that determines the default error message used by Active
14
+ # Record. Works for both existing Rails 2.1 and Rails 2.2 with the newly
15
+ # introduced I18n module used for localization.
16
+ #
17
+ # default_error_message(:blank)
18
+ # default_error_message(:too_short, :count => 5)
19
+ # default_error_message(:too_long, :count => 60)
20
+ def default_error_message(key, values = {})
21
+ if Object.const_defined?(:I18n) # Rails >= 2.2
22
+ result = I18n.translate("activerecord.errors.messages.#{key}", values)
23
+ if result =~ /^translation missing/
24
+ I18n.translate("errors.messages.#{key}", values)
25
+ else
26
+ result
27
+ end
28
+ else # Rails <= 2.1.x
29
+ ::ActiveRecord::Errors.default_error_messages[key] % values[:count]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,60 @@
1
+ module Ubazu
2
+ module Rspec # :nodoc:
3
+ module Matchers
4
+ module ActiveRecord # :nodoc:
5
+
6
+ # Ensures that the model field value is included in specified array.
7
+ #
8
+ # Options:
9
+ # * <tt>with_message</tt> - value the test expects to find in
10
+ # <tt>errors.on(:attribute)</tt>. <tt>Regexp</tt> or <tt>String</tt>.
11
+ # Defaults to the translation for <tt>:blank</tt>.
12
+ #
13
+ # Examples:
14
+ # it { should validate_inclusion_of(:name).in(:array) }
15
+ # it { should validate_inclusion_of(:name).in(:array)
16
+ # with_message(/is not optional/) }
17
+ #
18
+ def validate_inclusion_of(attr)
19
+ ValidateInclusionOfMatcher.new(attr)
20
+ end
21
+
22
+ class ValidateInclusionOfMatcher < ValidationMatcher # :nodoc:
23
+
24
+ def in(array)
25
+ @array = array
26
+ self
27
+ end
28
+
29
+ def with_message(message)
30
+ @expected_message = message if message
31
+ self
32
+ end
33
+
34
+ def matches?(instance)
35
+ @instance = instance
36
+ super(instance)
37
+
38
+ @expected_message ||= :blank
39
+ !@instance.valid? and @instance.errors.include? @expected_message
40
+ end
41
+
42
+ def description
43
+ "ensured inclusion of #{@attribute} in #{@array.inspect}"
44
+ end
45
+
46
+ private
47
+
48
+ def blank_value
49
+ if collection?
50
+ []
51
+ else
52
+ nil
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ module Ubazu
2
+ module Rspec # :nodoc:
3
+ module Matchers
4
+ module ActiveRecord # :nodoc:
5
+
6
+ class ValidationMatcher # :nodoc:
7
+
8
+ attr_reader :failure_message
9
+
10
+ def initialize(attribute)
11
+ @attribute = attribute
12
+ end
13
+
14
+ def negative_failure_message
15
+ @negative_failure_message || @failure_message
16
+ end
17
+
18
+ def matches?(subject)
19
+ @subject = subject
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ require 'ubazu/rspec/matchers/active_record/helpers'
2
+ require 'ubazu/rspec/matchers/active_record/validation_matcher'
3
+ require 'ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher'
4
+
5
+ module Ubazu
6
+ module Rspec
7
+ module Matchers
8
+ # = Matchers for your active record models
9
+ #
10
+ # These matchers will test most of the validations and associations for your
11
+ # ActiveRecord models.
12
+ #
13
+ # describe User do
14
+ # it { should validate_presence_of(:name) }
15
+ # it { should validate_presence_of(:phone_number) }
16
+ # %w(abcd 1234).each do |value|
17
+ # it { should_not allow_value(value).for(:phone_number) }
18
+ # end
19
+ # it { should allow_value("(123) 456-7890").for(:phone_number) }
20
+ # it { should_not allow_mass_assignment_of(:password) }
21
+ # it { should have_one(:profile) }
22
+ # it { should have_many(:dogs) }
23
+ # it { should have_many(:messes).through(:dogs) }
24
+ # it { should belong_to(:lover) }
25
+ # end
26
+ #
27
+ module ActiveRecord
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/ubazu.rb ADDED
@@ -0,0 +1,6 @@
1
+ if defined?(RSpec)
2
+ require 'ubazu/rspec/matchers/active_record'
3
+ else
4
+ # require 'shoulda/matchers/integrations/test_unit'
5
+ end
6
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'ubazu'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestUbazu < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
data/ubazu.gemspec ADDED
@@ -0,0 +1,68 @@
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 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ubazu}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Silviu Rosu"]
12
+ s.date = %q{2011-04-25}
13
+ s.description = %q{A collections of utilities to be used in different projects: ..., rspec expectations, etc.}
14
+ s.email = %q{silviu.rosu@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "README",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/LICENSE.txt",
28
+ "lib/ubazu.rb",
29
+ "lib/ubazu/rspec/matchers/active_record.rb",
30
+ "lib/ubazu/rspec/matchers/active_record/helpers.rb",
31
+ "lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb",
32
+ "lib/ubazu/rspec/matchers/active_record/validation_matcher.rb",
33
+ "test/helper.rb",
34
+ "test/test_ubazu.rb",
35
+ "ubazu.gemspec"
36
+ ]
37
+ s.homepage = %q{http://github.com/silviurosu/ubazu}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.6.2}
41
+ s.summary = %q{Practical utilities to use in projects}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_ubazu.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ end
68
+
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubazu
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Silviu Rosu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-25 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
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: bundler
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: jeweler
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rcov
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ description: "A collections of utilities to be used in different projects: ..., rspec expectations, etc."
82
+ email: silviu.rosu@gmail.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - README
89
+ - README.rdoc
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README
95
+ - README.rdoc
96
+ - Rakefile
97
+ - VERSION
98
+ - lib/LICENSE.txt
99
+ - lib/ubazu.rb
100
+ - lib/ubazu/rspec/matchers/active_record.rb
101
+ - lib/ubazu/rspec/matchers/active_record/helpers.rb
102
+ - lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb
103
+ - lib/ubazu/rspec/matchers/active_record/validation_matcher.rb
104
+ - test/helper.rb
105
+ - test/test_ubazu.rb
106
+ - ubazu.gemspec
107
+ has_rdoc: true
108
+ homepage: http://github.com/silviurosu/ubazu
109
+ licenses:
110
+ - MIT
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.6.2
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Practical utilities to use in projects
141
+ test_files:
142
+ - test/helper.rb
143
+ - test/test_ubazu.rb