factory_girl_rails 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,19 @@
1
+ Copyright (c) 2010 Joe Ferris and thoughtbot, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ = factory_girl
2
+
3
+ factory_girl is a fixtures replacement with a straightforward definition
4
+ syntax, support for multiple build strategies (saved instances, unsaved
5
+ instances, attribute hashes, and stubbed objects), and support for multiple
6
+ factories for the same class (user, admin_user, and so on), including factory
7
+ inheritance.
8
+
9
+ == Rails
10
+
11
+ factory_girl_rails provides Rails integration for factory_girl. All
12
+ Rails-specific features are only compatible with Rails 3.
13
+
14
+ Currenty, automatic factory definition loading is the only Rails-specific feature.
15
+
16
+ == Download
17
+
18
+ Github: http://github.com/thoughtbot/factory_girl_rails/tree/master
19
+
20
+ Gem:
21
+ gem install factory_girl_rails
22
+
23
+ == Configuration
24
+
25
+ Add factory_girl Rails to your Gemfile:
26
+
27
+ gem 'factory_girl_rails'
28
+
29
+ == More Information
30
+
31
+ factory_girl: http://github.com/thoughtbot/factory_girl/tree/master
32
+
33
+ == Author
34
+
35
+ factory_girl_rails was written by Joe Ferris.
36
+
37
+ Thanks to all members of thoughtbot for inspiration, ideas, and funding.
38
+
39
+ Copyright 2010 Joe Ferris and thoughtbot[http://www.thoughtbot.com], inc.
@@ -0,0 +1,16 @@
1
+ require 'rake/gempackagetask'
2
+ require 'cucumber/rake/task'
3
+
4
+ eval("$specification = #{IO.read('factory_girl_rails.gemspec')}")
5
+ Rake::GemPackageTask.new($specification) do |package|
6
+ package.need_zip = true
7
+ package.need_tar = true
8
+ end
9
+
10
+ Cucumber::Rake::Task.new(:cucumber) do |t|
11
+ t.fork = true
12
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
13
+ end
14
+
15
+ desc "Default: run the cucumber scenarios"
16
+ task :default => :cucumber
@@ -0,0 +1,47 @@
1
+ Feature: automatically load step definitions
2
+
3
+ Scenario: generate a rails 3 application and use factory definitions
4
+ When I generate a new rails application
5
+ And I save the following as "Gemfile"
6
+ """
7
+ source "http://rubygems.org"
8
+ gem 'rails', '3.0.0.beta4'
9
+ gem 'sqlite3-ruby', :require => 'sqlite3'
10
+ gem 'factory_girl_rails', :path => '../../'
11
+ """
12
+ When I run "bundle lock"
13
+ And I save the following as "db/migrate/1_create_users.rb"
14
+ """
15
+ class CreateUsers < ActiveRecord::Migration
16
+ def self.up
17
+ create_table :users do |t|
18
+ t.string :name
19
+ end
20
+ end
21
+ end
22
+ """
23
+ When I run "rake db:migrate"
24
+ And I save the following as "app/models/user.rb"
25
+ """
26
+ class User < ActiveRecord::Base
27
+ end
28
+ """
29
+ When I save the following as "test/factories.rb"
30
+ """
31
+ Factory.define :user do |user|
32
+ user.name 'Frank'
33
+ end
34
+ """
35
+ When I save the following as "test/unit/user_test.rb"
36
+ """
37
+ require 'test_helper'
38
+
39
+ class UserTest < ActiveSupport::TestCase
40
+ test "use factory" do
41
+ user = Factory(:user)
42
+ assert_equal 'Frank', user.name
43
+ end
44
+ end
45
+ """
46
+ When I run "rake test"
47
+ Then I should see "1 tests, 1 assertions, 0 failures, 0 errors"
@@ -0,0 +1,32 @@
1
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
2
+ TEMP_ROOT = File.join(PROJECT_ROOT, 'tmp').freeze
3
+ APP_NAME = 'testapp'.freeze
4
+ RAILS_ROOT = File.join(TEMP_ROOT, APP_NAME).freeze
5
+
6
+ Before do
7
+ FileUtils.rm_rf(TEMP_ROOT)
8
+ FileUtils.mkdir_p(TEMP_ROOT)
9
+ @terminal = Terminal.new
10
+ end
11
+
12
+ When /^I generate a new rails application$/ do
13
+ @terminal.cd(TEMP_ROOT)
14
+ @terminal.run("rails new #{APP_NAME}")
15
+ end
16
+
17
+ When /^I save the following as "([^\"]*)"$/ do |path, string|
18
+ FileUtils.mkdir_p(File.join(RAILS_ROOT, File.dirname(path)))
19
+ File.open(File.join(RAILS_ROOT, path), 'w') { |file| file.write(string) }
20
+ end
21
+
22
+ When /^I run "([^\"]*)"$/ do |command|
23
+ @terminal.cd(RAILS_ROOT)
24
+ @terminal.run(command)
25
+ end
26
+
27
+ Then /^I should see "([^\"]*)"$/ do |expected_text|
28
+ unless @terminal.output.include?(expected_text)
29
+ raise("Got terminal output:\n#{@terminal.output}\n\nExpected output:\n#{expected_text}")
30
+ end
31
+ end
32
+
@@ -0,0 +1,36 @@
1
+ require 'fileutils'
2
+
3
+ class Terminal
4
+ attr_reader :output, :status
5
+
6
+ def initialize
7
+ @cwd = FileUtils.pwd
8
+ @output = ""
9
+ @status = 0
10
+ @logger = Logger.new(File.join(TEMP_ROOT, 'terminal.log'))
11
+ end
12
+
13
+ def cd(directory)
14
+ @cwd = directory
15
+ end
16
+
17
+ def run(command)
18
+ output << "#{command}\n"
19
+ FileUtils.cd(@cwd) do
20
+ logger.debug(command)
21
+ result = `#{command} 2>&1`
22
+ logger.debug(result)
23
+ output << result
24
+ end
25
+ @status = $?
26
+ end
27
+
28
+ def echo(string)
29
+ logger.debug(string)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :logger
35
+ end
36
+
@@ -0,0 +1,2 @@
1
+ require 'factory_girl_rails/railtie'
2
+
@@ -0,0 +1,15 @@
1
+ require 'factory_girl'
2
+ require 'rails'
3
+
4
+ class Factory
5
+ class Railtie < Rails::Railtie
6
+ config.after_initialize do
7
+ Factory.definition_file_paths = [
8
+ File.join(Rails.root, 'test', 'factories'),
9
+ File.join(Rails.root, 'spec', 'factories')
10
+ ]
11
+ Factory.find_definitions
12
+ end
13
+ end
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factory_girl_rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Joe Ferris
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-11 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: -1848230024
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
33
+ - beta4
34
+ version: 3.0.0.beta4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: factory_girl
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 9
46
+ segments:
47
+ - 1
48
+ - 3
49
+ version: "1.3"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rake
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: rspec
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: cucumber
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ type: :development
93
+ version_requirements: *id005
94
+ description: |-
95
+ factory_girl_rails provides integration between
96
+ factory_girl and rails 3 (currently just automatic factory definition
97
+ loading)
98
+ email: jferris@thoughtbot.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files: []
104
+
105
+ files:
106
+ - LICENSE
107
+ - Rakefile
108
+ - README.rdoc
109
+ - lib/factory_girl_rails/railtie.rb
110
+ - lib/factory_girl_rails.rb
111
+ - features/load_definitions.feature
112
+ - features/step_definitions/rails_steps.rb
113
+ - features/support/terminal.rb
114
+ has_rdoc: true
115
+ homepage: http://thoughtbot.com/projects/factory_girl_rails
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options: []
120
+
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.3.7
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: factory_girl_rails provides integration between factory_girl and rails 3
148
+ test_files:
149
+ - features/load_definitions.feature
150
+ - features/step_definitions/rails_steps.rb
151
+ - features/support/terminal.rb