2011-12-13 7 views

risposta

85

I metodi sono the same; sono forniti per rendere più leggibili le specifiche in inglese in base al corpo del test. Considera questi due:

describe Array do 
    describe "with 3 items" do 
    before { @arr = [1, 2, 3] } 

    specify { @arr.should_not be_empty } 
    specify { @arr.count.should eq(3) } 
    end 
end 

describe Array do 
    describe "with 3 items" do 
    subject { [1, 2, 3] } 

    it { should_not be_empty } 
    its(:count) { should eq(3) } 
    end 
end 
+6

Sei corretto, Brandon, 'it' e' specifica' sono metodi identici. Puoi vedere dove sono definiti [qui nella fonte] (https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example_group.rb#L53-67). –

+1

Ottima presa! Incredibile quello che puoi trovare leggendo la fonte. :) aggiornerò la risposta. –

+2

Ecco un esempio con i nomi dei metodi degli esempi di dicembre 2013: https://gist.github.com/Dorian/7893586 (ad esempio, specificare, mettere a fuoco, ...) – Dorian

Problemi correlati