Ruby 我的Rspec测试一直不及格,但它看起来应该能工作

Ruby 我的Rspec测试一直不及格,但它看起来应该能工作,ruby,rspec,Ruby,Rspec,以下是测试: 我在这里定义了关键数据: let('bot_response') { {'bot_response' => 'the response contains <SETPROFILE><KEY>test_key</KEY><VALUE>TEST-SETPROFILE-VALUE</VALUE></SETPROFILE>'} } 我在这里断言测试条件: expect(bot_response['

以下是测试:

我在这里定义了关键数据:

  let('bot_response') {
    {'bot_response' => 'the response contains <SETPROFILE><KEY>test_key</KEY><VALUE>TEST-SETPROFILE-VALUE</VALUE></SETPROFILE>'}
  }
我在这里断言测试条件:

expect(bot_response['bot_response']).to eq("the response contains")
以下是实际方法的关键部分:

bot_response['bot_response'] = bot_response['bot_response'].gsub(/<SETPROFILE>(.*)<\/SETPROFILE>/, '').strip
return bot_response
bot_response['bot_response']=bot_response['bot_response'].gsub(/(.*)/,'').strip
返回bot\u响应
我的测试失败,原因如下:

 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>"
Failure/Error:expect(响应['bot\u response'])到eq(“响应包含”)
预期:“响应包含”
Get:“响应包含test\u keyTEST-SETPROFILE-VALUE”
但我不明白为什么。我是rspec的新手,实际上不确定我是否做对了,尤其是
let

expect(response['bot_response']).to eq("the response contains")
上面的测试期望两个字符串相同。如果要检查字符串的一部分,请尝试:

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

有关其他选项,请参见。

我希望它们相同。它应该去掉标签上的东西。哦,我误解了你的问题。您能否以连续的方式发布规范代码以及您正在测试的方法。您可以删除不相关的部分。我这样问是因为有两个
let(bot\u response){…}
语句,一个bot\u response['bot\u response']赋值。
expect(bot_response['bot_response']).to include("the response contains")