Skip to content

Commit

Permalink
spec_helper.rbに、factrygirlを使うためのメソッドを定義する
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshifumi0521 committed Sep 19, 2012
1 parent 1034b40 commit a9d4e04
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added app/.DS_Store
Binary file not shown.
Binary file added spec/.spec_helper.rb.swp
Binary file not shown.
16 changes: 8 additions & 8 deletions spec/factories/articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
#FactoryGirlのデータを定義する。
FactoryGirl.define do

factory :article do
title "初めてのブログ"
body "ブログはじめました"
end
#factory :article do
# title "初めてのブログ"
# body "ブログはじめました"
#end

#parentを利用して、articleのデータを引き継ぐ
factory :copy,:parent => :article do
title "ブログ"
end

#sequenceを使って、ユニークのデータをつくる場合
#factory :article do
# sequence(:title) { |n| "初めてのブログ_#{n}" }
# body "ブログはじめました"
#end
factory :article do
sequence(:title) { |n| "初めてのブログ_#{n}" }
body "ブログはじめました"
end

end

Expand Down
26 changes: 26 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#coding: utf-8
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
Expand All @@ -24,4 +25,29 @@
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true


#heplerに、FactoryGirlのデータをつくったり、データベースにいれたりするメソッドを定義する。
def create_article(params = {})
FactoryGirl.create(:article,params)
end

def build_article(params ={})
FactoryGirl.build(:article,params)
end















end
27 changes: 27 additions & 0 deletions spec/spec_helper.rb~
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end

0 comments on commit a9d4e04

Please sign in to comment.