diff --git a/lib/chibineko/rspec/matcher.rb b/lib/chibineko/rspec/matcher.rb index 5edc3b4..a34ed34 100644 --- a/lib/chibineko/rspec/matcher.rb +++ b/lib/chibineko/rspec/matcher.rb @@ -7,16 +7,10 @@ end description do - "should be complete." + "should be passed." end - + failure_message do |actual| - if actual.execute? - # NG - "expected that #{actual.item} should be completed." - else - # 未実施 - "expected that #{actual.item} should be executed." - end + "expected that #{actual.item} should be passed." end end diff --git a/spec/chibineko/rspec/matcher_spec.rb b/spec/chibineko/rspec/matcher_spec.rb new file mode 100644 index 0000000..f79680f --- /dev/null +++ b/spec/chibineko/rspec/matcher_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +require 'securerandom' +RSpec.describe :be_ok do + subject { be_ok } + + let(:passed) do + item = double('passed') + allow(item).to receive(:ok?) { true } + item + end + + let(:failed) do + item = double('failed') + item_desc = SecureRandom.uuid + allow(item).to receive(:ok?) { false } + allow(item).to receive(:execute?) { true } + allow(item).to receive(:item) { item_desc } + item + end + + let(:not_started) do + item = double('not_started') + item_desc = SecureRandom.uuid + allow(item).to receive(:ok?) {false} + allow(item).to receive(:execute?) {false} + allow(item).to receive(:item) { item_desc } + item + end + + its(:description) { should eq "should be passed." } + describe "match" do + it { expect(subject.matches?(passed)).to be_truthy } + it { expect(subject.matches?(failed)).to be_falsy } + it { expect(subject.matches?(not_started)).to be_falsy } + end + + it "failure_message include testitem.item" do + subject.matches?(not_started) + expect(subject.failure_message).to include(not_started.item) + end + +end diff --git a/spec/chibineko/testitem_spec.rb b/spec/chibineko/testitem_spec.rb index fc6a291..4f48df1 100644 --- a/spec/chibineko/testitem_spec.rb +++ b/spec/chibineko/testitem_spec.rb @@ -4,13 +4,13 @@ RSpec.describe Chibineko::TestItem do HEADERS = ["-","-","-","-","","",""] - it { expect(described_class).to be_a(Class) } subject { described_class.new(row, "http://www.example.com",1) } let(:row) do data = ['group1', 'group2', 'group3', nil, "item", "OK", "memo"] CSV::Row.new(HEADERS, data) end + it { expect(described_class).to be_a(Class) } its(:memo) { should eq "memo" } its(:item) { should eq "item" } its(:status) { should eq "OK" } @@ -23,14 +23,11 @@ end [:ok?, :ng?, :pending?, :skip?, :execute?].each do |m| - shared_examples "#{m}" do |lit, b| - it "#{m} returns #{b} when #status is \"#{lit}\"" do + shared_examples "#{m}" do |lit, truthy_or_falsy| + it "#{m} returns #{truthy_or_falsy} when #status is \"#{lit}\"" do subject.status = lit - if b - expect(subject.send(m)).to(be_truthy) - else - expect(subject.send(m)).to(be_falsy) - end + matcher = truthy_or_falsy ? be_truthy : be_falsy + expect(subject.send(m)).to(matcher) end end end