使用RSpec测试导轨金属/机架?

Mat*_*rby 3 rack rspec ruby-on-rails

假设我有一个名为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
Run Code Online (Sandbox Code Playgroud)

我明白了:

undefined method `post' for #<ActiveSupport::TestCase::Subclass_1:0x1058b3098>
Run Code Online (Sandbox Code Playgroud)

:post如果测试没有显式用于Controller ,RSpec似乎没有加载该方法.我试过指定:type => :controller无济于事.

Dav*_*sky 6

rspec具有包含rails集成测试(通过机架)的集成规范.把这个规格放进去吧./spec/integration/preview_spec.rb.