开发者

How do I test this Sinatra Method?

开发者 https://www.devze.com 2023-01-16 08:27 出处:网络
Trivial Sinatra application: require \'rubygems\' require \'sinatra/base\' require \'haml\' class InfoController < Sinatra::Base

Trivial Sinatra application:

require 'rubygems'
require 'sinatra/base'
require 'haml'

class InfoController < Sinatra::Base
  get "/" do
    haml :index
  end
end

And my test:

describe InfoController do
  include Rack::Test::Methods

  def app
    InfoController
  end

  it "should return the index page when visiting the root of the site" do    
   开发者_高级运维 get '/'
    last_response.should be_ok
  end
end

But I do not want to test whether or not the haml method worked, I just want to test that the index view was rendered.

How would you test that? Redefine the haml method? Mock the haml method somehow?


What about testing the actual markup that was rendered?

last_response.body.should match(/your text/)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号