2011-11-12 14 views

risposta

8

qualcosa di simile:

test_method.values_at("key1", "key2").should_not include(nil) 
+1

questo non funzionerà se uno dei valori dell'hash è in realtà 'nil'. 'hash.keys.should = ~ [: key1,: key2]' dovrebbe fare il trucco. –

9

che avrei scritto:

describe MyObject do 
    describe "#my_method" do 
    subject(:my_method) { MyObject.new.my_method } 

    it { is_expected.to be_a_kind_of(Hash) } 
    specify { expect(my_method.keys).to include(:key1, :key2) } 
    specify { expect(my_method.values).not_to include(nil) } 
    end 
end 

può accadere che si deve utilizzare i tasti tra virgolette "key1", "key2". Altrimenti potrebbe generare un errore.

Problemi correlati