title: Undefined method error while running rspec test
body: <p>All,</p>
  
  <p>I am getting the following undefined method errors below when running my rspec tests.  When I have gotten this error before I had a method misspelled or my order of execution caused it.  I checked both along with some other posts on StackOverflow, but nothing helped.  Can anyone offer any guidance?</p>
  
  <p><strong>Rspec Failures:</strong></p>
  
  <pre><code>FFFF
  
  Failures:
  
  1) Post vote methods #up_votes counts the number of votes with value = 1
   Failure/Error: expect(@post.up_votes ).to eq(3)
   NoMethodError:
     undefined method `up_votes' for #&lt;Post:0x007fe92f381a38&gt;
   # ./spec/models/post_spec.rb:14:in `block (4 levels) in &lt;top (required)&gt;'
  
   2) Post vote methods #down_votes counts the number of votes with values = -1
   Failure/Error: expect(@post.down_votes ).to eq(2)
   NoMethodError:
     undefined method `down_votes' for #&lt;Post:0x007fe92a18c228&gt;
   # ./spec/models/post_spec.rb:20:in `block (4 levels) in &lt;top (required)&gt;'
  
   3) Post vote methods #points returns the sum of all down and up votes
   Failure/Error: expect(@post.points ).to eq(1) # 3 - 2
   NoMethodError:
     undefined method `points' for #&lt;Post:0x007fe92986c620&gt;
   # ./spec/models/post_spec.rb:26:in `block (4 levels) in &lt;top (required)&gt;'
  
   4) Vote validations value validation only allows -1 or 1 as values
   Failure/Error: expect(@post.up_votes).to eq((-1) || eq(1))
   NoMethodError:
     undefined method `up_votes' for nil:NilClass
   # ./spec/models/vote_spec.rb:5:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p><strong>Post_rspec</strong></p>
  
  <pre><code>require 'rails_helper'
  
  describe Post do
   describe "vote methods" do
  
   before do
    @post = Post.create(title: 'Post title', body: 'Post bodies must be pretty long.')
    3.times { @post.votes.create(value: 1) }
    2.times { @post.votes.create(value: -1) }
   end
  
  describe '#up_votes' do
    it "counts the number of votes with value = 1" do
      expect(@post.up_votes ).to eq(3)
    end
  end
  
  describe '#down_votes' do
    it "counts the number of votes with values = -1" do
      expect(@post.down_votes ).to eq(2)
    end
  end
  
  describe '#points' do
    it "returns the sum of all down and up votes" do
      expect(@post.points ).to eq(1) # 3 - 2
    end
  end
  end
  end 
  </code></pre>
  
  <p><strong>vote_spec file</strong></p>
  
  <pre><code>describe Vote do
   describe "validations" do
    describe "value validation" do
    it "only allows -1 or 1 as values" do
      expect(@post.up_votes).to eq((-1) || eq(1)) 
    end
   end
   end
   end
  </code></pre>
  
  <p><strong>Post.rb</strong></p>
  
  <pre><code> class Post &lt; ActiveRecord::Base
   has_many :comments, dependent: :destroy
   has_many :votes
   has_one :summary
   belongs_to :user #means the post table has the user table's primary key in it
   belongs_to :topic
   mount_uploader :avatar, AvatarUploader
   default_scope {order('created_at DESC')}
  
   validates :title, length: {minimum: 5},  presence: true
   validates :body,  length: {minimum: 20}, presence: true
  
  
  
  def markdown_title
  (render_as_markdown).render(self.title).html_safe
  end
  
  
  def markdown_body
  (render_as_markdown).render(self.body).html_safe
  end
  
  private
  
  def render_as_markdown
  renderer = Redcarpet::Render::HTML.new
  extensions = {fenced_code_blocks: true}
  redcarpet = Redcarpet::Markdown.new(renderer, extensions)
  #return redcarpet
   end
  
  
   end
  </code></pre>