mini_factory 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README +32 -0
  2. data/Rakefile.rb +33 -0
  3. data/lib/mini_factory.rb +31 -0
  4. metadata +55 -0
data/README ADDED
@@ -0,0 +1,32 @@
1
+ mini_factory is simple factory builder
2
+
3
+ Put following line in your test enviroment file:
4
+ config.gem 'daeltar-mini_factory', :source => 'http://gems.github.com', :lib => 'mini_factory'
5
+
6
+ Create some factories under Rails test directory in file called factories.rb:
7
+
8
+ Factory.define :account do
9
+ {
10
+ :login => "alexis",
11
+ :password => "topsecret"
12
+ }
13
+ end
14
+
15
+ Example usage of factory in your tests:
16
+
17
+ test "xml" do
18
+ xml = Factory.build(:account).to_xml # build but not save object
19
+ assert !xml.include?("account-id")
20
+ end
21
+
22
+ test "should authenticate user" do
23
+ account = Factory.create(:account) # creates and save object
24
+ assert_equal Account.authenticate('alexis', 'topsecret'), account
25
+ end
26
+
27
+ test "should create account" do
28
+ assert_difference('Account.count') do
29
+ post :create, :account => Factory.attributes_for(:account) # returns hash
30
+ end
31
+ end
32
+
data/Rakefile.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ spec = Gem::Specification.new do |s|
5
+ s.name = %q{mini_factory}
6
+ s.version = "0.2"
7
+ s.summary = %q{mini_factory is simple factory builder}
8
+ s.description = %q{}
9
+
10
+ s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'test/**/*.rb']
11
+ s.require_path = 'lib'
12
+ #s.test_files = Dir[*['test/**/*_test.rb']]
13
+
14
+ #s.has_rdoc = true
15
+
16
+ s.authors = ["daeltar"]
17
+ s.email = %q{daeltar@gmail.com}
18
+ s.homepage = "http://github.com/daeltar/mini_factory"
19
+
20
+ s.platform = Gem::Platform::RUBY
21
+ end
22
+
23
+ Rake::GemPackageTask.new spec do |pkg|
24
+ pkg.need_tar = true
25
+ pkg.need_zip = true
26
+ end
27
+
28
+ desc "Generate a gemspec file"
29
+ task :gemspec do
30
+ File.open("#{spec.name}.gemspec", 'w') do |f|
31
+ f.write spec.to_ruby
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module Factory
2
+
3
+ def self.define(name, &block)
4
+ @@factories ||= {}
5
+ @@factories[name.to_sym] = block.call
6
+ end
7
+
8
+ def self.attributes_for(name, attributes = {})
9
+ @@factories[name.to_sym].merge(attributes)
10
+ end
11
+
12
+ def self.build(name, attributes = {})
13
+ obj = Kernel.const_get(name.to_s.capitalize).new()
14
+ self.attributes_for(name, attributes).each do |k, v|
15
+ obj.send(:"#{k}=", v)
16
+ end
17
+ obj
18
+ end
19
+
20
+ def self.create(name, attributes = {})
21
+ obj = self.build(name, attributes)
22
+ obj.save!
23
+ obj
24
+ end
25
+
26
+ end
27
+
28
+ # Load factories
29
+ Rails.configuration.after_initialize do
30
+ require File.join(RAILS_ROOT, 'test', 'factories')
31
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini_factory
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.2"
5
+ platform: ruby
6
+ authors:
7
+ - daeltar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-25 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: daeltar@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - Rakefile.rb
27
+ - lib/mini_factory.rb
28
+ has_rdoc: false
29
+ homepage: http://github.com/daeltar/mini_factory
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.1
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: mini_factory is simple factory builder
54
+ test_files: []
55
+