module Cog::SpecHelpers::Matchers
Extra should
or should_not
matchers for RSpec. Check out {#match_maker} for help writing new matchers.
Public Instance Methods
The target {Invocation} should write something to STDERR, indicating an error @return [nil]
# File lib/cog/spec_helpers/matchers.rb, line 13 def complain match_maker do message { "to [write something|not write anything] to STDERR" } test { !error.empty? } end end
The target {Invocation} should do something, as determined by standard output @return [nil]
# File lib/cog/spec_helpers/matchers.rb, line 37 def do_something match_maker do message { "to [write something|not write anything] to STDOUT" } test { !lines.empty? } end end
The target {Invocation} should create a file at the given path
@param path [String] path to check for a file after the invocation @return [nil]
# File lib/cog/spec_helpers/matchers.rb, line 23 def make(path) match_maker do message { "to [create|not create] #{path}" } before do @existed = File.exists? path end test do !@existed && File.exists?(path) end end end
Makes it easier to write RSpec matchers for testing cog
command invocations @yield self
is set to an instance of {MatchMaker} @example
def show_help match_maker do message { "to [show|not show] the default help text, got #{lines.first.inspect}" } test { (/help.*code gen/ =~ lines[1]) } end end
# File lib/cog/spec_helpers/matchers/match_maker.rb, line 109 def match_maker(&block) m = MatchMaker.new m.instance_eval &block m end
The target {Invocation} should write the given list of lines to standard output @param x [Array<String>, Regexp] a list of lines to match against standard output @return [nil]
# File lib/cog/spec_helpers/matchers.rb, line 47 def output(x) match_maker do message do if x.is_a? Regexp "to [write|not write] #{x.inspect} to STDOUT" else "to [write|not write] #{x.join "\n"} to STDOUT" end end test do if x.is_a? Regexp x =~ lines.join("\n") else lines.zip(x).all? {|a, b| a.strip == b.to_s.strip} end end end end
The target {Invocation} should output the default help text @return [nil]
# File lib/cog/spec_helpers/matchers.rb, line 68 def show_help match_maker do message { "to [show|not show] the default help text, got #{lines.first.inspect}" } test { (/help.*code gen/ =~ lines[1]) } end end