mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
Backported fixes from 1.1
This commit is contained in:
parent
dd737af03e
commit
9a874a8322
10 changed files with 70 additions and 85 deletions
2
.bundle/config
Normal file
2
.bundle/config
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
BUNDLE_DISABLE_SHARED_GEMS: "1"
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ factory_girl-*.gem
|
||||||
tmp
|
tmp
|
||||||
rdoc
|
rdoc
|
||||||
coverage
|
coverage
|
||||||
|
pkg
|
||||||
|
|
6
Gemfile
Normal file
6
Gemfile
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
source "http://rubygems.org"
|
||||||
|
gem "cucumber"
|
||||||
|
gem "aruba"
|
||||||
|
gem "rake"
|
||||||
|
gem "rspec"
|
||||||
|
|
40
Gemfile.lock
Normal file
40
Gemfile.lock
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
GEM
|
||||||
|
remote: http://rubygems.org/
|
||||||
|
specs:
|
||||||
|
aruba (0.2.3)
|
||||||
|
background_process
|
||||||
|
cucumber (~> 0.9.0)
|
||||||
|
background_process (1.2)
|
||||||
|
builder (2.1.2)
|
||||||
|
cucumber (0.9.2)
|
||||||
|
builder (~> 2.1.2)
|
||||||
|
diff-lcs (~> 1.1.2)
|
||||||
|
gherkin (~> 2.2.5)
|
||||||
|
json (~> 1.4.6)
|
||||||
|
term-ansicolor (~> 1.0.5)
|
||||||
|
diff-lcs (1.1.2)
|
||||||
|
gherkin (2.2.8)
|
||||||
|
json (~> 1.4.6)
|
||||||
|
term-ansicolor (~> 1.0.5)
|
||||||
|
json (1.4.6)
|
||||||
|
rake (0.8.7)
|
||||||
|
rspec (2.0.0)
|
||||||
|
rspec-core (= 2.0.0)
|
||||||
|
rspec-expectations (= 2.0.0)
|
||||||
|
rspec-mocks (= 2.0.0)
|
||||||
|
rspec-core (2.0.0)
|
||||||
|
rspec-expectations (2.0.0)
|
||||||
|
diff-lcs (>= 1.1.2)
|
||||||
|
rspec-mocks (2.0.0)
|
||||||
|
rspec-core (= 2.0.0)
|
||||||
|
rspec-expectations (= 2.0.0)
|
||||||
|
term-ansicolor (1.0.5)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
aruba
|
||||||
|
cucumber
|
||||||
|
rake
|
||||||
|
rspec
|
2
Rakefile
2
Rakefile
|
@ -1,3 +1,5 @@
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler/setup'
|
||||||
require 'rake/gempackagetask'
|
require 'rake/gempackagetask'
|
||||||
require 'cucumber/rake/task'
|
require 'cucumber/rake/task'
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ Gem::Specification.new do |s|
|
||||||
s.test_files = Dir['spec/**/*_spec.rb', 'features/**/*']
|
s.test_files = Dir['spec/**/*_spec.rb', 'features/**/*']
|
||||||
s.authors = ["Joe Ferris"]
|
s.authors = ["Joe Ferris"]
|
||||||
s.email = %q{jferris@thoughtbot.com}
|
s.email = %q{jferris@thoughtbot.com}
|
||||||
s.homepage = "http://thoughtbot.com/projects/factory_girl_rails"
|
s.homepage = "http://github.com/thoughtbot/factory_girl_rails"
|
||||||
s.add_runtime_dependency('rails', '>= 3.0.0.beta4')
|
s.add_runtime_dependency('railties', '>= 3.0.0')
|
||||||
s.add_runtime_dependency('factory_girl', '~> 1.3')
|
s.add_runtime_dependency('factory_girl', '~> 1.3')
|
||||||
s.add_development_dependency('rake')
|
s.add_development_dependency('rake')
|
||||||
s.add_development_dependency('rspec')
|
s.add_development_dependency('rspec')
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
Feature: automatically load step definitions
|
Feature: automatically load step definitions
|
||||||
|
|
||||||
|
@disable-bundler
|
||||||
Scenario: generate a rails 3 application and use factory definitions
|
Scenario: generate a rails 3 application and use factory definitions
|
||||||
When I generate a new rails application
|
When I successfully run "rails new testapp"
|
||||||
And I save the following as "Gemfile"
|
And I cd to "testapp"
|
||||||
"""
|
And I add "factory_girl_rails" from this project as a dependency
|
||||||
source "http://rubygems.org"
|
When I successfully run "bundle install"
|
||||||
gem 'rails', '3.0.0.beta4'
|
And I write to "db/migrate/1_create_users.rb" with:
|
||||||
gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
||||||
gem 'factory_girl_rails', :path => '../../'
|
|
||||||
"""
|
|
||||||
When I run "bundle lock"
|
|
||||||
And I save the following as "db/migrate/1_create_users.rb"
|
|
||||||
"""
|
"""
|
||||||
class CreateUsers < ActiveRecord::Migration
|
class CreateUsers < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
|
@ -20,19 +16,19 @@ Feature: automatically load step definitions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
When I run "rake db:migrate"
|
When I successfully run "rake db:migrate --trace"
|
||||||
And I save the following as "app/models/user.rb"
|
And I write to "app/models/user.rb" with:
|
||||||
"""
|
"""
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
When I save the following as "test/factories.rb"
|
When I write to "test/factories.rb" with:
|
||||||
"""
|
"""
|
||||||
Factory.define :user do |user|
|
Factory.define :user do |user|
|
||||||
user.name 'Frank'
|
user.name 'Frank'
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
When I save the following as "test/unit/user_test.rb"
|
When I write to "test/unit/user_test.rb" with:
|
||||||
"""
|
"""
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
|
@ -43,5 +39,5 @@ Feature: automatically load step definitions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
When I run "rake test"
|
When I successfully run "rake test --trace"
|
||||||
Then I should see "1 tests, 1 assertions, 0 failures, 0 errors"
|
Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors"
|
||||||
|
|
|
@ -1,32 +1,3 @@
|
||||||
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
When /^I add "([^"]+)" from this project as a dependency$/ do |gem_name|
|
||||||
TEMP_ROOT = File.join(PROJECT_ROOT, 'tmp').freeze
|
append_to_file('Gemfile', %{gem "#{gem_name}", :path => "#{PROJECT_ROOT}"})
|
||||||
APP_NAME = 'testapp'.freeze
|
|
||||||
RAILS_ROOT = File.join(TEMP_ROOT, APP_NAME).freeze
|
|
||||||
|
|
||||||
Before do
|
|
||||||
FileUtils.rm_rf(TEMP_ROOT)
|
|
||||||
FileUtils.mkdir_p(TEMP_ROOT)
|
|
||||||
@terminal = Terminal.new
|
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I generate a new rails application$/ do
|
|
||||||
@terminal.cd(TEMP_ROOT)
|
|
||||||
@terminal.run("rails new #{APP_NAME}")
|
|
||||||
end
|
|
||||||
|
|
||||||
When /^I save the following as "([^\"]*)"$/ do |path, string|
|
|
||||||
FileUtils.mkdir_p(File.join(RAILS_ROOT, File.dirname(path)))
|
|
||||||
File.open(File.join(RAILS_ROOT, path), 'w') { |file| file.write(string) }
|
|
||||||
end
|
|
||||||
|
|
||||||
When /^I run "([^\"]*)"$/ do |command|
|
|
||||||
@terminal.cd(RAILS_ROOT)
|
|
||||||
@terminal.run(command)
|
|
||||||
end
|
|
||||||
|
|
||||||
Then /^I should see "([^\"]*)"$/ do |expected_text|
|
|
||||||
unless @terminal.output.include?(expected_text)
|
|
||||||
raise("Got terminal output:\n#{@terminal.output}\n\nExpected output:\n#{expected_text}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
3
features/support/env.rb
Normal file
3
features/support/env.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
require 'aruba'
|
||||||
|
|
||||||
|
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
|
@ -1,36 +0,0 @@
|
||||||
require 'fileutils'
|
|
||||||
|
|
||||||
class Terminal
|
|
||||||
attr_reader :output, :status
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
@cwd = FileUtils.pwd
|
|
||||||
@output = ""
|
|
||||||
@status = 0
|
|
||||||
@logger = Logger.new(File.join(TEMP_ROOT, 'terminal.log'))
|
|
||||||
end
|
|
||||||
|
|
||||||
def cd(directory)
|
|
||||||
@cwd = directory
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(command)
|
|
||||||
output << "#{command}\n"
|
|
||||||
FileUtils.cd(@cwd) do
|
|
||||||
logger.debug(command)
|
|
||||||
result = `#{command} 2>&1`
|
|
||||||
logger.debug(result)
|
|
||||||
output << result
|
|
||||||
end
|
|
||||||
@status = $?
|
|
||||||
end
|
|
||||||
|
|
||||||
def echo(string)
|
|
||||||
logger.debug(string)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
attr_reader :logger
|
|
||||||
end
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue