Created
June 12, 2014 14:18
-
-
Save gguerini/d7bb9f430278df8fd66c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :render_chart do |expected| | |
include JsonHelpers | |
match do |actual| | |
valid_caption? && valid_value? && valid_label? | |
end | |
failure_message_for_should do |actual| | |
failure_msg = "Expected that: \n" | |
failure_msg << " - Caption would be '#{@expected_caption}', but got '#{json_response.chart.caption}' \n" unless valid_caption? | |
failure_msg << " - Value would be '#{@expected_value}', but got '#{json_response.data.first.value}' \n" unless valid_value? | |
failure_msg << " - Label would be '#{@expected_label}', but got '#{json_response.data.first.label}' \n" unless valid_label? | |
failure_msg | |
end | |
chain :with_caption do |expected_caption| | |
@expected_caption = expected_caption | |
end | |
chain :with_value do |expected_value| | |
@expected_value = expected_value | |
end | |
chain :with_label do |expected_label| | |
@expected_label = expected_label | |
end | |
def valid_caption? | |
json_response.chart.present? && (@expected_caption.nil? || json_response.chart.caption == @expected_caption) | |
end | |
def valid_value? | |
json_response.data.present? && (@expected_value.nil? || json_response.data.first.value == @expected_value) | |
end | |
def valid_label? | |
json_response.data.present? && (@expected_label.nil? || json_response.data.first.label == @expected_label) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment