0

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

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

2 Comments

I want them to be the same. It should strip out what is in the tag.
Oh, I misread your question. Can you post the spec code in a continuous manner and the method you are testing. You can remove the irrelevant sections. I'm asking because there are two let(bot_response) { ... } statements, one bot_response['bot_response'] assignment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.