is an admin’ do subject { described_class.make(:admin => true) } it { should be_admin } end context ‘when the subject is not an admin’ do subject { described_class.make(:admin => false) } it { should_not be_admin } end end 129݄21༵ۚ
is an admin’ do subject { described_class.make(:admin => true) } it { should be_admin } end context ‘when the subject is not an admin’ do subject { described_class.make(:admin => false) } it { should_not be_admin } end end Example group 129݄21༵ۚ
is an admin’ do subject { described_class.make(:admin => true) } it { should be_admin } end context ‘when the subject is not an admin’ do subject { described_class.make(:admin => false) } it { should_not be_admin } end end Example group Example group 129݄21༵ۚ
is an admin’ do subject { described_class.make(:admin => true) } it { should be_admin } end context ‘when the subject is not an admin’ do subject { described_class.make(:admin => false) } it { should_not be_admin } end end Code example Code example 129݄21༵ۚ
is an admin’ do subject { described_class.make(:admin => true) } it { should be_admin } end context ‘when the subject is not an admin’ do subject { described_class.make(:admin => false) } it { should_not be_admin } end end Expectation Expectation 129݄21༵ۚ
is an admin’ do subject { described_class.make(:admin => true) } it { should be_admin } end context ‘when the subject is not an admin’ do subject { described_class.make(:admin => false) } it { should_not be_admin } end end Spec file 129݄21༵ۚ
class can be initialized with an Array let(:collection) { described_class.new([7, 2, 4]) } context “initialized with 3 items” do it “says it has three items” do collection.size.should eq(3) end end describe “#include?” do context “with an item that is in the collection” do it “returns true” do collection.should be_include(7) end end end end 129݄21༵ۚ
measurement_methods| measurement_methods.each do |measurement_method| describe “##{measurement_method}“ do it “should return #{measurement}” do subject.send(measurement_method).should eq(measurement) end end end end describe Array, “with 3 items” do subject { [1, 2, 3] } it_behaves_like “a measurable object”, 3, [:size, :length] end describe String, “of 6 ASCII-chars” do subject { “FooBar” } it_behaves_like “a measurable object”, 6, [:bytesize, :size, :length] end 129݄21༵ۚ
measurement_methods| measurement_methods.each do |measurement_method| describe “##{measurement_method}“ do it “should return #{measurement}” do subject.send(measurement_method).should eq(measurement) end end end end describe Array, “with 3 items” do subject { [1, 2, 3] } it_behaves_like “a measurable object”, 3, [:size, :length] end describe String, “of 6 ASCII-chars” do subject { “FooBar” } it_behaves_like “a measurable object”, 6, [:bytesize, :size, :length] end 129݄21༵ۚ
measurement_methods| measurement_methods.each do |measurement_method| describe “##{measurement_method}“ do it “should return #{measurement}” do subject.send(measurement_method).should eq(measurement) end end end end describe Array, “with 3 items” do subject { [1, 2, 3] } it_behaves_like “a measurable object”, 3, [:size, :length] end describe String, “of 6 ASCII-chars” do subject { “FooBar” } it_behaves_like “a measurable object”, 6, [:bytesize, :size, :length] end 129݄21༵ۚ
using ‘include_context’” do include_context ‘shared stuff’ specify ‘access things defined in the included shared context’ do shared_method.should eq(‘it works’) shared_let[‘arbitrary’].should eq(‘object’) @some_var.should be(:some_value) subject.should eq(‘this is the subject’) end end 129݄21༵ۚ
do before { @some_var = :some_value } def shared_method “it works” end let(:shared_let) { { ‘arbitrary’ => ‘object’ } } subject { ‘this is the subject’ } end 129݄21༵ۚ
do before { @some_var = :some_value } def shared_method “it works” end let(:shared_let) { { ‘arbitrary’ => ‘object’ } } subject { ‘this is the subject’ } end 129݄21༵ۚ
shared context by metadata”, :foo => :bar do specify ‘access things defined in the included shared context’ do shared_method.should eq(‘it works’) shared_let[‘arbitrary’].should eq(‘object’) @some_var.should be(:some_value) subject.should eq(‘this is the subject’) end end 129݄21༵ۚ
shared context by metadata”, :foo => :bar do specify ‘access things defined in the included shared context’ do shared_method.should eq(‘it works’) shared_let[‘arbitrary’].should eq(‘object’) @some_var.should be(:some_value) subject.should eq(‘this is the subject’) end end 129݄21༵ۚ
# this is pending pending(“reason”, :if => false) { expectations } # this is not pending pending(“reason”, :unless => true) { expectations } # this is not pending pending(“reason”, :unless => false) { expectations } # this is pending 129݄21༵ۚ
it ‘has `:fast => true` metadata’ do example.metadata[:fast].should eq(true) end it ‘has `:bar => true` metadata’ do example.metadata[:bar].should eq(true) end it ‘has `:baz => 42` metadata’ do example.metadata[:baz].should eq(42) end it ‘has `:hoge => true` metadata’, :hoge do example.metadata[:hoge].should eq(true) end end 129݄21༵ۚ
it ‘has `:fast => true` metadata’ do example.metadata[:fast].should eq(true) end it ‘has `:bar => true` metadata’ do example.metadata[:bar].should eq(true) end it ‘has `:baz => 42` metadata’ do example.metadata[:baz].should eq(42) end it ‘has `:hoge => true` metadata’, :hoge do example.metadata[:hoge].should eq(true) end end 129݄21༵ۚ
be_true actual.should eql(expected) it is same as: (actual.eql? expected).should be_true actual.should equal(expected) it is same as: (actual.equal? expected).should be_true 129݄21༵ۚ
be < expected actual.should be <= expected actual.should =~ /expression/ actual.should match(/expression/) actual.should be_within(delta).of(expected) it is same as: (actual - expected).abs.should be <= delta 129݄21༵ۚ
% expected == 0 end failure_message_for_should do |actual| “expected that #{actual} would be a multiple of #{expected}” end failure_message_for_should_not do |actual| “expected that #{actual} wouldn’t be a multiple of #{expected}” end description do “be multiple of #{expected}” # used for auto-generated description end end 129݄21༵ۚ
# pass end describe 9 do it { should_not be_a_multiple_of(4) } # pass end describe 9 do it { should be_a_multiple_of(4) } #=> “expected that 9 would be a multiple of 4” end describe 9 do it { should_not be_a_multiple_of(3) } #=> “expected that 9 wouldn’t be a multiple of 3” end 129݄21༵ۚ