minitest_rails_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright © 2013 SUSE
2
+
3
+ Author: Dominik Bamberger ( bamboo [at] suse.com)
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,28 @@
1
+ # Minitest Rails Tools
2
+
3
+
4
+ This is a collection of little helpers to make working with Rails and Minitest a bit easier.
5
+
6
+ NOTE: This is definitely a work in progress. I use this gem in two of my applications and will continue to add stuff to it, as well as fixing bugs.
7
+
8
+
9
+ It allows you to write stuff like this in your Minitest Spec:
10
+
11
+
12
+ subject { FactoryGirl.create :foo }
13
+
14
+ must_belong_to :faz
15
+ must_have_one :boo
16
+ must_have_many :bams
17
+ must_have_many_through :bars, :bams
18
+ must_have_and_belong_to_many :berks
19
+
20
+ must_validate_presence_of :lol
21
+ must_validate_uniqueness_of :lol
22
+
23
+ Additionally, you can define a helper as your subject:
24
+
25
+ subject { helper :foo_helper }
26
+
27
+
28
+ Copyright © 2013 SUSE released under the MIT license. For full details see LICENSE included in this distribution.
@@ -0,0 +1,36 @@
1
+ # Allows for some automagic association tests.
2
+
3
+ def must_belong_to(association_name)
4
+ it "belongs_to :#{association_name.to_s.parameterize.underscore}" do
5
+ subject.association(association_name).must_be_kind_of(ActiveRecord::Associations::BelongsToAssociation)
6
+ subject.send(association_name)
7
+ end
8
+ end
9
+
10
+ def must_have_one(association_name)
11
+ it "has_one :#{association_name.to_s.parameterize.underscore}" do
12
+ subject.association(association_name).must_be_kind_of(ActiveRecord::Associations::HasOneAssociation)
13
+ subject.send(association_name)
14
+ end
15
+ end
16
+
17
+ def must_have_many(association_name)
18
+ it "has_many :#{association_name.to_s.parameterize.underscore}" do
19
+ subject.association(association_name).must_be_kind_of(ActiveRecord::Associations::HasManyAssociation)
20
+ subject.send(association_name).must_be_kind_of(Array)
21
+ end
22
+ end
23
+
24
+ def must_have_many_through(association_name, association_name_through)
25
+ it "has_many :#{association_name.to_s.parameterize.underscore} through :#{association_name_through.to_s.parameterize.underscore}" do
26
+ subject.association(association_name).must_be_kind_of(ActiveRecord::Associations::HasManyThroughAssociation)
27
+ subject.send(association_name).must_be_kind_of(Array)
28
+ end
29
+ end
30
+
31
+ def must_have_and_belong_to_many(association_name)
32
+ it "has_and_belongs_to_many :#{association_name.to_s.parameterize.underscore}" do
33
+ subject.association(association_name).must_be_kind_of(ActiveRecord::Associations::HasAndBelongsToManyAssociation)
34
+ subject.send(association_name).must_be_kind_of(Array)
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ class HelperProxy
2
+
3
+ attr_accessor :current_methods
4
+
5
+ def initialize(name)
6
+ @current_methods ||= []
7
+ # Remove existing instance methods.
8
+ @current_methods.each do |method_name|
9
+ self.class.send(:remove_method, method_name)
10
+ end
11
+ # Add new instance methods from helper module.
12
+ klass = name.to_s.camelize.safe_constantize
13
+ @current_methods = klass.instance_methods
14
+ self.class.send(:include, klass)
15
+ end
16
+ end
17
+
18
+
19
+ module HelperExtension
20
+
21
+ def helper(name)
22
+ HelperProxy.new(name)
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ require 'association_matchers'
2
+ require 'validation_matchers'
3
+ require 'helper_extension'
@@ -0,0 +1,18 @@
1
+ # Allows for some automagic association tests.
2
+
3
+ def must_validate_presence_of(attribute_name)
4
+ it "validates_presence_of :#{attribute_name.to_s.parameterize.underscore}" do
5
+ subject.send "#{attribute_name}=".to_sym, nil
6
+ subject.valid?.must_equal false
7
+ subject.errors.messages[attribute_name.to_sym].must_include "can't be blank"
8
+ end
9
+ end
10
+
11
+ def must_validate_uniqueness_of(attribute_name)
12
+ it "validates_uniqueness_of :#{attribute_name.to_s.parameterize.underscore}" do
13
+ other = FactoryGirl.create subject.class.to_s.parameterize.underscore.to_sym
14
+ subject.send "#{attribute_name}=".to_sym, other.send(attribute_name)
15
+ subject.valid?.must_equal false
16
+ subject.errors.messages[attribute_name.to_sym].must_include "has already been taken"
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest_rails_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dominik Bamberger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A collection of little helpers to make working with Rails and Minitest
15
+ a bit easier.
16
+ email: bamboo@suse.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/minitest_rails_tools.rb
24
+ - lib/helper_extension.rb
25
+ - lib/association_matchers.rb
26
+ - lib/validation_matchers.rb
27
+ homepage: http://github.com/b4mboo/minitest_rails_tools
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.23
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Smoothen Minitest/Rails integration
51
+ test_files: []