shard-ameba/spec/spec_helper.cr

66 lines
1.3 KiB
Crystal
Raw Normal View History

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
2017-11-07 21:50:25 +00:00
struct DummyRule < Rule::Base
2017-11-22 06:44:29 +00:00
properties do
description : String = "Dummy rule that does nothing."
end
2017-11-01 20:05:41 +00:00
def test(source)
end
2017-10-30 20:00:01 +00:00
end
2017-11-30 21:50:07 +00:00
struct ErrorRule < Rule::Base
def test(source)
source.error self, 1, 1, "This rule always adds an error"
2017-11-30 21:50:07 +00:00
end
end
2017-11-01 20:05:41 +00:00
class DummyFormatter < Formatter::BaseFormatter
property started_sources : Array(Source)?
property finished_sources : Array(Source)?
property started_source : Source?
property finished_source : Source?
def started(sources)
@started_sources = sources
end
def source_finished(source : Source)
@started_source = source
end
def source_started(source : Source)
@finished_source = source
end
def finished(sources)
@finished_sources = sources
end
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.message}\n"
2017-11-01 20:05:41 +00:00
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