Skip to content

Commit

Permalink
adding factory girl
Browse files Browse the repository at this point in the history
  • Loading branch information
gdagley committed Sep 29, 2012
1 parent 16d0b87 commit 3c1dd3e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ group :development, :test do
gem "sqlite3"
gem "capybara"
gem "simplecov"
gem 'factory_girl_rails'
gem 'faker'
end

group :test do
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ GEM
excon (0.16.4)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (4.1.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.1.0)
factory_girl (~> 4.1.0)
railties (>= 3.0.0)
faker (1.1.2)
i18n (~> 0.5)
ffi (1.1.5)
font-awesome-sass-rails (2.0.0.0)
railties (>= 3.1.1)
Expand Down Expand Up @@ -266,6 +273,8 @@ DEPENDENCIES
cucumber-rails
database_cleaner
devise
factory_girl_rails
faker
font-awesome-sass-rails
guard-bundler
guard-cucumber
Expand Down
22 changes: 10 additions & 12 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ guard 'bundler' do
# watch(/^.+\.gemspec/)
end

guard 'cucumber' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end
# guard 'cucumber' do
# watch(%r{^features/.+\.feature$})
# watch(%r{^features/support/.+$}) { 'features' }
# watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
# end

guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)})
Expand All @@ -23,19 +23,17 @@ guard 'livereload' do
end

guard 'rspec' do
watch(%r{^spec/factories/.+\.rb$}) { |m| "spec/factories_spec.rb" }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/models/.+\.rb$}) { |m| "spec/factories_spec.rb" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end


Expand Down
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
require File.expand_path('../config/application', __FILE__)

BaseJumper::Application.load_tasks

if Rails.env.development? || Rails.env.test?
desc 'Run factory specs.'
RSpec::Core::RakeTask.new(:factory_specs) do |t|
t.pattern = './spec/factories_spec.rb'
end

task :spec => :factory_specs
end
7 changes: 7 additions & 0 deletions spec/factories/user_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :user do
email { Faker::Internet.email }
password 'monkey'
password_confirmation 'monkey'
end
end
12 changes: 12 additions & 0 deletions spec/factories_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://robots.thoughtbot.com/post/30994874643/testing-your-factories-first
require 'spec_helper'

FactoryGirl.factories.map(&:name).each do |factory_name|
describe "The #{factory_name} factory" do
it 'is valid' do
instance = FactoryGirl.build(factory_name)
instance.valid?.should be_true, instance.errors.full_messages.to_sentence
# build(factory_name).should be_valid
end
end
end
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false

# If repeating "FactoryGirl" is too verbose for you, you can mix the syntax
# methods in. This allows you to use the core set of syntax methods (build,
# build_stubbed, create, attributes_for, and their *_list counterparts) without
# having to call them on FactoryGirl directly.
config.include FactoryGirl::Syntax::Methods
end

0 comments on commit 3c1dd3e

Please sign in to comment.