Skip to content

Commit

Permalink
Made gemspec and gem support with jeweler
Browse files Browse the repository at this point in the history
  • Loading branch information
dsboulder committed Sep 18, 2010
1 parent 6b369d0 commit db88044
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
pkg/
24 changes: 19 additions & 5 deletions README
Expand Up @@ -6,7 +6,7 @@ Based on the code from fixture_scenarios, by Chris Wanstrath. Allows you to buil
Installing
==========

1. Install the plugin
1. Install as a plugin or gem: `gem install fixture_builder`
1. Create a file which configures and declares your fixtures (see below for example)
1. Require the above file in your `spec_helper.rb` or `test_helper.rb`

Expand All @@ -15,10 +15,11 @@ Example
=======

When using an object mother such as factory_girl it can be setup like the following:


# I usually put this file in spec/support/fixture_builder.rb
FixtureBuilder.configure do |fbuilder|
# rebuild fixtures automatically when these files change:
fbuilder.files_to_check += Dir["spec/factories/*.rb"]
fbuilder.files_to_check += Dir["spec/factories/*.rb", "spec/support/fixture_builder.rb"]

# now declare objects
fbuilder.factory do
Expand All @@ -33,12 +34,11 @@ The block passed to the factory method initiates the creation of the fixture fil
# users.yml
david:
created_at: 2010-09-18 17:21:23.926511 Z
updated_at: 2010-09-18 17:21:23.926511 Z
unique_name: david
id: 1

# products.yml
ipod:
i_pod:
name: iPod
id: 1

Expand Down Expand Up @@ -70,6 +70,20 @@ By default these are set as:
* select_sql: SELECT * FROM %s
* delete_sql: DELETE FROM %s

Sequence Collisions
===================

One problem with generating your fixtures is that sequences can collide. When the fixtures are generated only as needed, sometimes the process that generates the fixtures will be different than the process that runs the tests. This results in collisions when you still use factories in your tests. Here's a solution for FactoryGirl which resets sequences numbers to 1000 (to avoid conflicts with fixture data which should e sequenced < 1000) before the tests run:

FixtureBuilder.configure do |fbuilder|
...
end

# Have factory girl generate non-colliding sequences starting at 1000 for data created after the fixtures
Factory.sequences.each do |name, seq|
seq.instance_variable_set(:@value, 1000)
end



Copyright (c) 2009 Ryan Dy & David Stevenson, released under the MIT license
59 changes: 45 additions & 14 deletions Rakefile
@@ -1,23 +1,54 @@
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "fixture_builder"
gem.summary = %Q{Build YAML fixtures using object factories}
gem.description = %Q{FixtureBuilder allows testers to use their existing factories, like FactoryGirl, to generate high performance fixtures that can be shared across all your tests}
gem.email = "stellar256@hotmail.com"
gem.homepage = "http://github.com/rdy/fixture_builder"
gem.authors = ["Ryan Dy", "David Stevenson"]
gem.rubyforge_project = "fixture_builder"
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'rake/testtask'
require 'rake/rdoctask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end

task :test => :check_dependencies

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the fixture_builder plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

desc 'Generate documentation for the fixture_builder plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'FixtureBuilder'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.title = "fixture_builder #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
54 changes: 54 additions & 0 deletions fixture_builder.gemspec
@@ -0,0 +1,54 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{fixture_builder}
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ryan Dy", "David Stevenson"]
s.date = %q{2010-09-18}
s.description = %q{FixtureBuilder allows testers to use their existing factories, like FactoryGirl, to generate high performance fixtures that can be shared across all your tests}
s.email = %q{stellar256@hotmail.com}
s.extra_rdoc_files = [
"README"
]
s.files = [
"MIT-LICENSE",
"README",
"Rakefile",
"VERSION",
"fixture_builder.gemspec",
"init.rb",
"lib/fixture_builder.rb",
"tasks/fixture_builder.rake",
"test/fixture_builder_test.rb",
"test/test_helper.rb"
]
s.homepage = %q{http://github.com/rdy/fixture_builder}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{fixture_builder}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Build YAML fixtures using object factories}
s.test_files = [
"test/fixture_builder_test.rb",
"test/test_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
else
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
end
else
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
end
end

1 change: 0 additions & 1 deletion install.rb

This file was deleted.

1 change: 0 additions & 1 deletion uninstall.rb

This file was deleted.

0 comments on commit db88044

Please sign in to comment.