Created
August 21, 2012 07:01
-
-
Save a2ikm/3412907 to your computer and use it in GitHub Desktop.
->のテスト、自分ならこう書く http://d.hatena.ne.jp/sinsoku/20120820/1345470914
This file contains hidden or 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
| # coding: utf-8 | |
| require "spec_helper" | |
| describe User do | |
| describe "#admin?" do | |
| subject { user.admin? } | |
| context "管理者の場合" do | |
| let(:user) { User.new(role: "admin") } | |
| it { should be_true } | |
| end | |
| context "一般ユーザの場合" do | |
| let(:user) { User.new(role: nil) } | |
| it { should be_false } | |
| end | |
| end | |
| describe "#runnable_system?" do | |
| subject { user.runnable_system? } | |
| context "管理者がリンディさんの場合" do | |
| let(:user) { User.new(name: 'Lindi') } | |
| before { user.stub(admin?: true) } | |
| it { should be_true } | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
書き換えた点は次の4つ。
#hoge?のテストにshould be_hogeは使わない(RSpecの成分が入ってなんか気持ち悪い)ただ2つ目のテストはstubしちゃっていいのかわからない。
runnable_system?がadmin?依存なのかUserのname依存なのかわからないので。