title: Rspec: No route matches {:action=>"show", :controller=>"posts", :id=>nil}
body: <p>I'm trying to create a very simple blog using Rails, for my own education. It's the first Rails app I've ever created other than from working through tutorials.</p>
  
  <p>So far I just have a very simple model where each post has only a string for the title and a string for the content. Everything works fine and as expected in the browser, but I can't get the tests to pass.</p>
  
  <p>Here's are the failing test in my Rspec code (spec/requests/post_spec.rb):</p>
  
  <pre><code>require 'spec_helper'
  
  describe "Posts" do
  
    .
    .
    .
  
    describe "viewing a single post" do
  
      @post = Post.create(title: "The title", content: "The content")
  
      before { visit post_path(@post) }
  
      it { should have_selector('title',    text: @post.title) }
      it { should have_selector('h1',       text: @post.title) }
      it { should have_selector('div.post', text: @post.content) }
  
    end
  
  end
  </code></pre>
  
  <p>This gives me the same error message for all 3:</p>
  
  <pre><code>Failure/Error: before { visit post_path(@post) }
       ActionController::RoutingError:
         No route matches {:action=&gt;"show", :controller=&gt;"posts", :id=&gt;nil}
  </code></pre>
  
  <p>So it seems to me the problem is that the line @post = Post.create(...) is creating a post without an id, or else it's not saving the post to the test database correctly. How do I fix this? And am I going about this the right way in the first place, or is there a better way I could be creating the test post/testing the page?</p>
  
  <p>This is only a problem in testing. When I view a single post in the browser everything looks fine. The Posts controller is: (I have edited this since posting the original question)</p>
  
  <pre><code>class PostsController &lt; ApplicationController
    def new
      @post = Post.new
    end
  
    def create
      @post = Post.new(params[:post])
      if @post.save
        redirect_to posts_path, :notice =&gt; "Post successfully created!"
      end
    end
  
    def index
    end
  
    def show
      @post = Post.find(params[:id])
    end
  end
  </code></pre>
  
  <p>And here's the Post model in its entirety:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    attr_accessible :content, :title
  
    validates :content, presence: true
    validates :title,   presence: true
  end
  </code></pre>
  
  <p>config/routes:</p>
  
  <pre><code>Blog::Application.routes.draw do
      resources :posts
  
      root to: 'posts#index'
  end
  </code></pre>
  
  <p>app/views/posts/show.html.erb:</p>
  
  <pre><code>&lt;% provide(:title, @post.title) %&gt;
  
  &lt;h1&gt;&lt;%= @post.title %&gt;&lt;/h1&gt;
  
  &lt;div class="post"&gt;&lt;%= @post.content %&gt;&lt;/div&gt;
  </code></pre>