Created
October 22, 2013 05:04
-
-
Save kjirou/7095484 to your computer and use it in GitHub Desktop.
RSpecの使い方メモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# RSpec の動作確認 | |
# | |
shared_context '_dummy' do | |
# letは遅延評価で値をキャッシュする | |
let(:some_value) { 'Some value' } | |
end | |
shared_context '_create_rspec_test_user' do | |
User.create!(name: 'RSpec test user') | |
end | |
describe 'Test for RSpec' do | |
describe 'ダミーのshared_contextが定義され読み込めているか' do | |
# describe 直下に書く、it 内には書けない | |
include_context '_dummy' | |
subject { some_value } | |
it { should eq 'Some value' } # eq は値一致 | |
it { should_not be 'Some value' } # be は参照一致 | |
end | |
# create = インスタンス生成+保存、create! で失敗したら例外を投げる | |
# new = インスタンス生成、リレーション考慮しない。バリデーションもしない | |
# build = リレーションを考慮したインスタンス生成らしい? | |
# @TODO バリデーションを単体で実行するのは? | |
# @TODO DBのデータ削除のタイミングはいつ? | |
# @TODO User は type が NULL と言われて生成できない。STIの仕様か? | |
# @TODO リレーションを考慮した保存方法が不明 | |
describe 'DBを使ったテストデータの生成・保存' do | |
it 'Fooモデルを保存できる' do | |
Foo.create!(name: 'Test reader') | |
end | |
end | |
describe 'モデルインスタンスを生成する' do | |
it 'Barモデルを生成できる' do | |
# @TODO インスタンスを型チェックする方法は? | |
Bar.new(name: 'Dummy user', email:'dummy@example.com', password:'dummy123') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment