开发者

Ruby-on-Rails Tutorial for static page

I working through the Ruby-on-Rails Tutorial book and I've got a perplexing problem that I can't figure out. I got rspec up and running with spork and it seems like a great system. However on the first test I've ran into something that is just crazy. The book says to create some static pages called home and contact, and then it instructs me in how to create a static page running the DBB of rspec. So I create the red spec for the about page

  describe "GET 'about'" do
    it "should be successful" do
      get 'about'
      response.should be_success
    end
  end

This fails as expected. Then I add a route to the to the routes.rb file

get "pages/about"

A controller to the pages_controller.rb file that adds a controller.

def about
end

I add a very simple static web page for the about page.

The book says that after doing this test should be green, or pass the tests. It doesn't. The really perplexing thing is that I can actually open the simple web page by typing in the address.

http://localhost:3000/pages/about

I've tried changing the 'about' to 'home' so that I essentially run the home test twice. That works OK so I know that there isn't a syntax problem. I've changed everything around so that I see that the test fails at different points.

I finally, our of desperation thought that I'd t开发者_StackOverflow中文版ry asking a question. It seems very basic, but since I'm reading this book to learn the system, I really don't know where to start looking.


When you change the routes.rb file, you need to restart spork.


first, don't worry about asking noob questions here. The only rule in stack overflow is that you shouldn't be asking exact duplicates of existing questions :)

I don't see anything particularly wrong with what you did. I would try adding a debugging statement right above your assertion line

describe "GET 'about'" do
  it "should be successful" do
    get 'about'
    puts response.inspect
    response.should be_success
  end
end

(inspect is a way to get objects to output something more meaningful then their location in memory)

If the output doesn't really shed any light on the problem, try adding it to your post, and maybe we can help you figure it out


I like to start the server ("rails s") in it's own iTerm window and I type/edit code in another. If you have the server running, it should show you the requested URL that is failing as it's log is generated. Might be helpful to see what is actually being requested.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜