Sha256: 397cf404659c3a48b165d09edc320f592087aa50c6dfe978e40db3bcbc26babd
Contents?: true
Size: 1.1 KB
Versions: 3
Compression:
Stored size: 1.1 KB
Contents
require 'timeout' module Support module Pattern def pattern(pattern, options = nil, &block) description = "pattern %p" % pattern if options description << " with options %p" % [options] instance = subject_for(pattern, options) else instance = subject_for(pattern) end context description do subject(:pattern, &instance) its(:to_s) { should be == pattern } its(:inspect) { should be == "#<#{described_class}:#{pattern.inspect}>" } its(:names) { should be_an(Array) } example 'string should be immune to external change' do subject.to_s.replace "NOT THE PATTERN" subject.to_s.should be == pattern end instance_eval(&block) end end def subject_for(pattern, *args) instance = Timeout.timeout(1) { described_class.new(pattern, *args) } proc { instance } rescue Timeout::Error => error proc { raise Timeout::Error, "could not compile #{pattern.inspect} in time", error.backtrace } rescue Exception => error proc { raise error } end end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
mustermann19-0.3.1 | spec/support/pattern.rb |
mustermann-0.3.1 | spec/support/pattern.rb |
mustermann-0.3.0 | spec/support/pattern.rb |