Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from tinsep19/t/matcher
Browse files Browse the repository at this point in the history
T/matcher
  • Loading branch information
tinsep19 committed May 23, 2015
2 parents d4d28e9 + 368652c commit e82f129
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
12 changes: 3 additions & 9 deletions lib/chibineko/rspec/matcher.rb
Expand Up @@ -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
42 changes: 42 additions & 0 deletions 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
13 changes: 5 additions & 8 deletions spec/chibineko/testitem_spec.rb
Expand Up @@ -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" }
Expand All @@ -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
Expand Down

0 comments on commit e82f129

Please sign in to comment.