hash_factory 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
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.
data/Manifest ADDED
@@ -0,0 +1,10 @@
1
+ MIT-LICENSE
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ config/initializers/factory_in_console.rb
6
+ lib/hash_factory.rb
7
+ lib/hash_factory_builder.rb
8
+ tasks/hash_factory_tasks.rake
9
+ test/hash_factory_test.rb
10
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,99 @@
1
+ = HashFactory
2
+
3
+ == The simplest Rails test factory ever.
4
+
5
+ == Install
6
+
7
+ braid add git://github.com/brentgreeff/hash_factory.git -p
8
+
9
+ Add this line to the top of test/test_helper.rb
10
+
11
+ require 'test_help' # this should already be here
12
+ HashFactory.setup
13
+
14
+
15
+ == Lets start with the calling code
16
+
17
+ I like to setup my test data, right there in the
18
+ test where everyone can see it.
19
+
20
+ * Along the lines of
21
+
22
+ test "A User with a blank last name should be invalid" do
23
+ @user = create_user :last_name => ''
24
+ assert @user.invalid?
25
+ end
26
+
27
+ == A few things to notice:
28
+
29
+ I don't call Factory.create_user.
30
+ All that 'Factory' typing just adds noise and makes my fingers sore.
31
+
32
+ I define the arguments relevant to the test explicitly.
33
+ I dont need to look at the implementation to see if the user has a last_name.
34
+
35
+ I assume the factory handles the rest and passes me a 'VALID' instance.
36
+
37
+ == Test things in isolation
38
+ A factory that returns an invalid instance will eventually cause a failure that ripples
39
+ through your test code. Face slapping will ensue.
40
+
41
+
42
+ == How does it work?
43
+
44
+ * create a factories directory:
45
+
46
+ mkdir test/factories
47
+
48
+ Add a module to this folder and the methods
49
+ automatically become available in your tests.
50
+
51
+ * Mine tend to look like this:
52
+
53
+ module UserFactory
54
+
55
+ def create_user(options={})
56
+ build :user, user_options(options)
57
+ end
58
+
59
+ def user_options(options={})
60
+ {
61
+ :first_name => 'Jim',
62
+ :last_name => 'Bean',
63
+ :email => "jim@example.com",
64
+ :account => options[:account] || create_account
65
+ }.merge(options)
66
+ end
67
+ end
68
+
69
+
70
+ Add as many or as few files as you like.
71
+
72
+ The advantage of using this plugin is you can build your objects any way you like.
73
+
74
+ Don't worry about protected attributes
75
+ the 'build' method handles it for you.
76
+
77
+ === Pluralization Issues
78
+
79
+ Be sure to update your 'initializers/inflections.rb'
80
+ If you get an Constant missing error when loading a factory.
81
+
82
+
83
+ === Factory love in the console.
84
+
85
+ Call
86
+
87
+ require 'hash_factory'
88
+ HashFactory.load_in(self)
89
+
90
+ Or event better
91
+
92
+ copy the file:
93
+
94
+ config/initializers/factory_in_console.rb
95
+
96
+ and it's always there waiting for you.
97
+
98
+
99
+ Copyright (c) 2009 [Brent Greeff], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'echoe'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the hash_factory plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the hash_factory plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'HashFactory'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ Echoe.new('hash_factory', '1.0.0') do |p|
27
+ p.description = "Simple Rails factories"
28
+ p.url = "http://github.com/brentgreeff/hash_factory"
29
+ p.author = "Brent Greeff"
30
+ p.email = ""
31
+ p.ignore_pattern = ["init.rb", "install.rb", "uninstall.rb"]
32
+ p.development_dependencies = []
33
+ end
34
+
35
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,4 @@
1
+ if $0 == 'irb'
2
+ require 'hash_factory'
3
+ HashFactory.load_in(self)
4
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{hash_factory}
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brent Greeff"]
9
+ s.date = %q{2010-03-23}
10
+ s.description = %q{Simple Rails factories}
11
+ s.email = %q{}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/hash_factory.rb", "lib/hash_factory_builder.rb", "tasks/hash_factory_tasks.rake"]
13
+ s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "config/initializers/factory_in_console.rb", "lib/hash_factory.rb", "lib/hash_factory_builder.rb", "tasks/hash_factory_tasks.rake", "test/hash_factory_test.rb", "test/test_helper.rb", "Manifest", "hash_factory.gemspec"]
14
+ s.homepage = %q{http://github.com/brentgreeff/hash_factory}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hash_factory", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{hash_factory}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Simple Rails factories}
20
+ s.test_files = ["test/hash_factory_test.rb", "test/test_helper.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ class HashFactory
2
+ def self.setup
3
+ self.load_in(ActiveSupport::TestCase)
4
+ end
5
+
6
+ def self.load_in(klass)
7
+ require 'hash_factory_builder'
8
+ klass.send :include, HashFactoryBuilder
9
+
10
+ factories.each do |file|
11
+ require file
12
+ klass.send :include, get_class(file)
13
+ end
14
+ end
15
+
16
+ def self.factories
17
+ Dir[factories_path + '/*_factory.rb']
18
+ end
19
+
20
+ def self.get_class(file)
21
+ file.split('/').last.gsub('.rb', '').classify.constantize
22
+ end
23
+
24
+ def self.factories_path
25
+ "#{RAILS_ROOT}/test/factories"
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module HashFactoryBuilder
2
+ def build(class_name, options)
3
+ new_obj = class_name.to_s.pluralize.classify.constantize.new
4
+ new_obj.send :attributes=, options, false
5
+ new_obj.save!
6
+
7
+ return new_obj
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hash_factory do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class HashFactoryTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_factory
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Brent Greeff
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-23 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Simple Rails factories
22
+ email: ""
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ - lib/hash_factory.rb
30
+ - lib/hash_factory_builder.rb
31
+ - tasks/hash_factory_tasks.rake
32
+ files:
33
+ - MIT-LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - config/initializers/factory_in_console.rb
37
+ - lib/hash_factory.rb
38
+ - lib/hash_factory_builder.rb
39
+ - tasks/hash_factory_tasks.rake
40
+ - test/hash_factory_test.rb
41
+ - test/test_helper.rb
42
+ - Manifest
43
+ - hash_factory.gemspec
44
+ has_rdoc: true
45
+ homepage: http://github.com/brentgreeff/hash_factory
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --line-numbers
51
+ - --inline-source
52
+ - --title
53
+ - Hash_factory
54
+ - --main
55
+ - README.rdoc
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ version: "1.2"
73
+ requirements: []
74
+
75
+ rubyforge_project: hash_factory
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Simple Rails factories
80
+ test_files:
81
+ - test/hash_factory_test.rb
82
+ - test/test_helper.rb