Satchel
Satchel

Reputation: 16734

my Rspec test keeps failing but it looks like it should work

Here is the test:

I define the key data here:

  let('bot_response') {
    {'bot_response' => 'the response contains <SETPROFILE><KEY>test_key</KEY><VALUE>TEST-SETPROFILE-VALUE</VALUE></SETPROFILE>'}
  }

I run the method I want to test here:

let('bot_response') {BotResponse.act_on_set_profile_tag(
    value,
    bot_client_id,
    bot_response
  )}

I assert the test condition here:

expect(bot_response['bot_response']).to eq("the response contains")

Here is the key part of the actual method:

bot_response['bot_response'] = bot_response['bot_response'].gsub(/<SETPROFILE>(.*)<\/SETPROFILE>/, '').strip
return bot_response

My test fails with the following:

 Failure/Error: expect(response['bot_response']).to eq("the response contains")

   expected: "the response contains"
        got: "the response contains <SETPROFILE><KEY>test_key</KEY><VALUE>TEST-SETPROFILE-VALUE</VALUE></SETPROFILE>"

But I cannot figure out why. I am new to rspec and actually am not sure if I am doing it right, particularly the let

Upvotes: 0

Views: 33

Answers (1)

roob
roob

Reputation: 1136

expect(response['bot_response']).to eq("the response contains")

The test above expects the two strings to be the same. If you want to check against a part of the string, try:

expect(bot_response['bot_response']).to include("the response contains")

See RSpec matchers for other options.

Upvotes: 2

Related Questions