English 中文(简体)
履历表
原标题:RSpec and weird tests results

我试图作一个简单的说明。 当在浏览器中测试时,便会做一些细微的工作。 当我试图与RSpec(2.5)进行一些测试时,它在对控制器进行以下测试时失败了。

Here s my create method:

def create
 @website = Website.new(params[:website])
 if @website.save

   flash[:notice] = "Website created."
   redirect_to(:action =>  list )
 else
   render( new )
 end
end

控制器测试:

describe WebsitesController do
  render_views
  .
  .
  .
  describe "POST  create " do
    before(:each) do
      @attr = { :adres => "www.excc.pl", :opis => "aaa "*22, :tagi => "aaa aaa aaa",
                :preview => File.new(Rails.root +  spec/fixtures/rails.png ),
                :preview_mini => File.new(Rails.root +  spec/fixtures/rails.png )}
    end
    describe "success" do
      it "should have the right title" do
        response.should have_selector("title", :content=>"Lista witryn w portfolio")
      end
    end
  .
  .
  .

这一检验的结果:

  1) WebsitesController POST  create  should have the right title
     Failure/Error: response.should have_selector("title", :content=>"Lista witryn    w portfolio")
     expected following output to contain a <title>Lista witryn w portfolio</title> tag:
     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
     # ./spec/controllers/websites_controller_spec.rb:34:in `block (4 levels) in

网站_ Controller_spec.rb:34 系指制造方法

然而,这一测试是正确的(关于不正确的数据,应当重新定位到有具体所有权的新地点):

it "should have the right title" do
    post :create, :website => @attr.merge(:adres => "")
    response.should have_selector("title", :content=>"Dodaj stronę WWW")
end

The second problem is... There was a time when I ve got a test result like this:

<html><body>You are being <a href="http://test.host/websites/list">redire cted</a>.</body></html>

......这给我带来了一些时间,直到我做完th(我并不真正知道什么)和去了。 然而,当我认为它今后能够恢复我幸福的废墟时,它使我感到悲伤。

任何这方面的想法都将受到高度赞赏。

问题回答

我很想知道这里问什么,但我认为问题不是为成功/失败创造条件。 如果我正确理解,如果你通过空白<条码>:adres属性,则该节应失败,该页应使<条码>>>>>>>>>>>>行动。 因此,你想要搁置<代码>create方法,并根据预期结果退回真实或虚假:

it "succeeds" do
  @website = mock_model(Website,:save=>true)
  Website.stub(:new) { @website }
  post :create, :website => {}
  # redirects
  response.should have_selector("etc etc")
end


it "fails" do
  @website = mock_model(Website,:save=>false)
  Website.stub(:new) { @website }
  post :create, :website => {}
  # renders  new 
  response.should_not have_selector("etc etc")
end

应在模型光谱中测试参数的有效性:

@website = Website.new(:adres=>"")
@website.should_not be_valid




相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签