require"set"
shared_examples_for "a collection"do
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)
endend
describe "#include?"do
context "with an an item that is in the collection"do
it "returns true"do
collection.include?(7).should be_true
endend
context "with an an item that is not in the collection"do
it "returns false"do
collection.include?(9).should be_false
endendendend
describe Arraydo
it_behaves_like "a collection"end
describe Setdo
it_behaves_like "a collection"end
ブロックを渡してやることもできるしパラメータを渡してやることもできる。
require"set"
shared_examples_for "a collection"do
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)
endend
describe "#include?"do
context "with an an item that is in the collection"do
it "returns true"do
collection.include?(7).should be_true
endend
context "with an an item that is not in the collection"do
it "returns false"do
collection.include?(9).should be_false
endendendend
describe Arraydo
it_behaves_like "a collection"end
describe Setdo
it_behaves_like "a collection"end
require"set"
shared_examples_for "a collection object"do
describe "<<"do
it "adds objects to the end of the collection"do
collection << 1
collection << 2
collection.to_a.should eq([1,2])
endendend
describe Arraydo
it_should_behave_like "a collection object"do
let(:collection) { Array.new }
endend
describe Setdo
it_should_behave_like "a collection object"do
let(:collection) { Set.new }
endend
require"set"
shared_examples_for "a collection object"do
describe "<<"do
it "adds objects to the end of the collection"do
collection << 1
collection << 2
collection.to_a.should eq([1,2])
endendend
describe Arraydo
it 'sample_examples_for_test'do
it_should_behave_like "a collection object"do
let(:collection) { Array.new }
endendend
describe Setdo
it_should_behave_like "a collection object"do
let(:collection) { Set.new }
endend
Failures:
1) Array sample_examples_for_test
Failure/Error: it_should_behave_like "a collection object" do
NoMethodError:
undefined method `it_should_behave_like' for #
# ./sample_spec.rb:15:in `block (2 levels) in '
事の発端をたどると、Android Bazar and Conference 2011 winterのボランティアスタッフに参加したことから始まる。
その頃は「OSSのコミュニティに貢献したい」という今考えると自分でもよくわからないモチベーションがあって、当時興味のあったAndroidのイベントでボランティアスタッフの募集があったので申し込んだら当選した。