Class: Speq::Question
- Inherits:
-
Object
- Object
- Speq::Question
- Defined in:
- lib/speq/question.rb,
lib/speq/string_fmt.rb
Overview
Records the question name, result, and constructs the corresponding matcher
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#question_name ⇒ Object
readonly
Returns the value of attribute question_name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(question_name, result, matcher) ⇒ Question
constructor
A new instance of Question.
- #outcome ⇒ Object
- #phrase ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(question_name, result, matcher) ⇒ Question
Returns a new instance of Question.
21 22 23 24 25 |
# File 'lib/speq/question.rb', line 21 def initialize(question_name, result, matcher) @question_name = question_name @result = result @matcher = matcher end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
19 20 21 |
# File 'lib/speq/question.rb', line 19 def matcher @matcher end |
#question_name ⇒ Object (readonly)
Returns the value of attribute question_name.
19 20 21 |
# File 'lib/speq/question.rb', line 19 def question_name @question_name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
19 20 21 |
# File 'lib/speq/question.rb', line 19 def result @result end |
Class Method Details
.for(result, question_name, *args, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/speq/question.rb', line 39 def self.for(result, question_name, *args, &block) matcher = Matcher.for(question_name, *args, &block) Question.new( question_name, result, matcher ) end |
.question?(method_name) ⇒ Boolean
15 16 17 |
# File 'lib/speq/question.rb', line 15 def self.question?(method_name) method_name.to_s.end_with?('?') end |
Instance Method Details
#outcome ⇒ Object
33 34 35 36 37 |
# File 'lib/speq/question.rb', line 33 def outcome matcher.match?(result) ? Outcome.pass : Outcome.fail rescue StandardError Outcome.error end |
#phrase ⇒ Object
27 28 29 30 31 |
# File 'lib/speq/question.rb', line 27 def phrase matcher.phrase(result) rescue StandardError => e QuestionError.new(@question_name, e.inspect).to_s end |
#to_s ⇒ Object
47 48 49 50 |
# File 'lib/speq/string_fmt.rb', line 47 def to_s "#{phrase}#{outcome.fail? ? " (result = #{result.inspect})" : ''}" .send(outcome.pass? ? :green : :red) end |