Sha256: c4237f507de363aabbb84f42094eb945a5d7c69dea0fbf08e2ef19848b7c9bb3
Contents?: true
Size: 1.5 KB
Versions: 3
Compression:
Stored size: 1.5 KB
Contents
require 'minitest/autorun' require 'cognition' class MatcherTest < Minitest::Test def test_raises_error_without_a_trigger assert_raises ArgumentError do _ = Cognition::Matcher.new(action: 'foo') end end def test_raises_error_without_an_action assert_raises ArgumentError do _ = Cognition::Matcher.new(trigger: 'foo') end end def test_matches_string msg = Cognition::Message.new('help') matcher = Cognition::Matcher.new('help', 'test', &Proc.new {}) assert matcher.matches?(msg) end def test_string_fails_with_invalid_message msg = Cognition::Message.new('Help') matcher = Cognition::Matcher.new('help', 'test', &Proc.new {}) refute matcher.matches?(msg) end def test_matches_regexp msg = Cognition::Message.new('ping') matcher = Cognition::Matcher.new(/ping/, 'test', &Proc.new {}) assert matcher.matches?(msg) end def test_regexp_fails_with_invalid_message msg = Cognition::Message.new('pink') matcher = Cognition::Matcher.new(/ping/, 'test', &Proc.new {}) refute matcher.matches?(msg) end def test_sets_response_on_attemp_if_matches msg = Cognition::Message.new('ping') matcher = Cognition::Matcher.new(/ping/, 'test', &Proc.new {'PONG'}) matcher.attempt(msg) assert_equal 'PONG', matcher.response end def test_returns_false_on_attemp_if_no_match msg = Cognition::Message.new('pink') matcher = Cognition::Matcher.new(/ping/, 'test', &Proc.new {'PONG'}) refute matcher.attempt(msg) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cognition-1.0.1 | test/test_matcher.rb |
cognition-1.0.0 | test/test_matcher.rb |
cognition-0.1.0 | test/test_matcher.rb |