tags: RSpec

RSpec's #to Method Takes the 2nd Argument As Its failing-message

Today I learned that RSpec's #to method takes the 2nd argument as its custom failing-message. expect(actual_value).to eq(expected_value), message Let's say we are going to test a JSON object. The following example expects a part of the JSON object response_json['eye_colour'] to be "blue". require 'net/https' require 'uri' require 'json' RSpec.describe do example do response = Net::HTTP.get_response(URI('https://swapi.dev/api/people/1/')) response_json = JSON.parse(response.body) expect(response_json['eye_colour']).to eq('blue') end end Unfortunately, this test fails and displays messages like this:

Read more →

Gentaro "hibariya" Terada

Otaka-no-mori, Chiba, Japan
Email me

Loves Ruby, Internet, and Programming.