2012-01-18 9 views
2

私の環境:RSpecはまずコンテキストを読み込み、before(:all)を読み込みます。どうして?

次のソースコードでRSpecの実行
jruby-1.5.3 
Rails 2.3.8 
RSpec 1.3.1 
Windows 7 (64-bit machine) 

、なぜ文のbefore(:each)前の文脈である「=>」の付いたRSpecの読み取りラインはありません。すべてのヘルプははるかに

 
def save_env 
    @host_os = Config::CONFIG['host_os'] 
end 

def restore_env 
    Config::CONFIG['host_os'] = @host_os 
end 

describe Manager::ManagerConfig do 
    before(:each) do 
    save_env 
    end 

    after(:each) do 
    restore_env 
    end 

    context "Within Linus/Solaris environment" do 
=> Config::CONFIG['host_os'] = 'linux' 

    it "should return the correct manager path under linux/solaris" do 
     # bar 
    end 

    it "should return the correct license path under windows env" do 
     # foo 
    end 
    end 
end 

答えて

3

コンテキストが内部クラスを設定し、それ内の線はそれぞれitbeforeafterが実行されるコードのブロックを作成することを除いて、ロード時に実行されようとしていると理解さ後で。

あなたがする必要があるのは、独自のbefore(:each)ブロックのconfig設定を包んで、順序は、あなたが期待するものになります:外before(:each)、そして内側のbefore(:each)、その後、it

before(:each) do 
    Config::CONFIG['host_os'] = 'linux' 
end 
関連する問題