如何用RSpec测试导轨金属机架在Ruby on Rails中的应用?
- 内容介绍
- 文章标签
- 相关推荐
本文共计290个文字,预计阅读时间需要2分钟。
ruby为了创建一个名为 `Preview` 的 Metal 类并使用 RSpec 进行测试,以下是修改后的代码内容:
rubyclass Preview # 假设 Preview 类有相应的功能来处理预览请求end
使用 RSpec 进行测试require 'spec_helper'
describe Preview do it should return the posted content do post /preview, params: { content: @title } expect(response.body).to eq(@ti) endend
以上代码定义了一个简单的 `Preview` 类,并使用 RSpec 测试框架来测试该类的某个功能。测试方法 `it should return the posted content` 检查当向 `/preview` 路径发送 POST 请求时,响应体是否正确返回了预期内容。
假设我有一个名为Preview的Metal类.如何使用RSpec进行测试?当我尝试:
require 'spec_helper' describe Preview do it "should return the posted content" do post "/preview", :content => "*title*" response.body.should == "*title*" end end
我明白了:
undefined method `post' for #<ActiveSupport::TestCase::Subclass_1:0x1058b3098>
似乎RSpec没有加载:post方法,如果测试没有显式为Controller.我已经尝试过指定:type => :控制器无济于事.
rspec具有包含rails集成测试(通过机架)的集成规范.只需将该规范放在./spec/integration/preview_spec.rb中即可.本文共计290个文字,预计阅读时间需要2分钟。
ruby为了创建一个名为 `Preview` 的 Metal 类并使用 RSpec 进行测试,以下是修改后的代码内容:
rubyclass Preview # 假设 Preview 类有相应的功能来处理预览请求end
使用 RSpec 进行测试require 'spec_helper'
describe Preview do it should return the posted content do post /preview, params: { content: @title } expect(response.body).to eq(@ti) endend
以上代码定义了一个简单的 `Preview` 类,并使用 RSpec 测试框架来测试该类的某个功能。测试方法 `it should return the posted content` 检查当向 `/preview` 路径发送 POST 请求时,响应体是否正确返回了预期内容。
假设我有一个名为Preview的Metal类.如何使用RSpec进行测试?当我尝试:
require 'spec_helper' describe Preview do it "should return the posted content" do post "/preview", :content => "*title*" response.body.should == "*title*" end end
我明白了:
undefined method `post' for #<ActiveSupport::TestCase::Subclass_1:0x1058b3098>
似乎RSpec没有加载:post方法,如果测试没有显式为Controller.我已经尝试过指定:type => :控制器无济于事.
rspec具有包含rails集成测试(通过机架)的集成规范.只需将该规范放在./spec/integration/preview_spec.rb中即可.
