lib/prickle/capybara/exceptions.rb in prickle-0.0.1 vs lib/prickle/capybara/exceptions.rb in prickle-0.0.2

- old
+ new

@@ -1,16 +1,39 @@ module Prickle module Capybara - class ElementNotFound < Exception - def initialize type, identifier, text, e - element_text = "Element" - element_text = "\e[1m#{type}\e[0m\e[31m" unless type == "*" - text_string = " and text \e[1m#{text}\e[0m\e[31m" unless text.nil? + class ElementNotFound < Exception; end; - raise "#{element_text} with properties \e[1m#{identifier.to_s}\e[0m\e[31m#{text_string} was not found.\nError: #{e.message}" + class Error + + def initialize type, identifier, text, caught_exception + @element_type = type + @element_identifier = identifier + @element_text = text + @caught_exception = caught_exception end - end + def message + "#{element_text} with properties #{identifier} #{text_string} was not found.\n\tError: #{@caught_exception.message}" + end + private + + def element_text + return highlight(@element_type) unless @element_type == "*" + "Element" + end + + def text_string + " and text #{highlight(@element_text)}" unless @element_text.nil? + end + + def identifier + highlight(@element_identifier.to_s) + end + + def highlight text + "\e[1m#{text}\e[0m\e[31m" + end + end end end