RSpec测试失败,未定义方法`respond_with'

时间:2016-12-07 06:13:56

标签: ruby-on-rails ruby rspec

我正在处理Rails API Tutorial并面临错误。每当我运行测试时,我都会

  1) Api::V1::UsersController PUT/PATCH #update when is not created
     Failure/Error: it { should respond_with 422 }

     NoMethodError:
       undefined method `respond_with' for #<RSpec::ExampleGroups::ApiV1UsersController::PUTPATCH
Update::WhenIsNotCreated:0x007f860e070eb8>
       Did you mean?  respond_to

我发现其他两个帖子(thisthis)指向一个非常相似的问题,但两个都没有解决。有人有解决方案吗?谢谢!

1 个答案:

答案 0 :(得分:2)

如上所述here,请尝试以下方法:

it { should respond_with 422 }

而不是

// Doing this reads inputStream for the first time
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
while ((line = br.readLine()) != null) {
    sb.append(line);
}

// Doing this reads inputStream for the second time, resulting in the error
InputStream is = new BufferedInputStream(inputStream);
Image image = ImageIO.read(is);