2017-10-26 16:46:58 +00:00
|
|
|
require "spec"
|
|
|
|
require "../src/ameba"
|
2017-10-30 20:00:01 +00:00
|
|
|
|
2017-11-01 20:05:41 +00:00
|
|
|
module Ameba
|
|
|
|
struct DummyRule < Ameba::Rule
|
|
|
|
def test(source)
|
|
|
|
end
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
2017-11-01 20:05:41 +00:00
|
|
|
|
|
|
|
struct BeValidExpectation
|
|
|
|
def match(source)
|
|
|
|
source.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message(source)
|
|
|
|
String.build do |str|
|
|
|
|
str << "Source expected to be valid, but there are errors:\n\n"
|
|
|
|
source.errors.each do |e|
|
|
|
|
str << " * #{e.rule.name}:#{e.pos} #{e.message}\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def negative_failure_message(source)
|
|
|
|
"Source expected to be invalid, but it is valid."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def be_valid
|
|
|
|
Ameba::BeValidExpectation.new
|
2017-11-01 10:49:03 +00:00
|
|
|
end
|