title: RSpec Expectations and ExpectationNotMetError
body: <p>Hello I have been following a course to further my understanding of cucumber. The course is a little old so i have had to update some rspec syntax from should to expect but otherwise have been following it very carefully. I cannot get this recent test to pass and i am rather lost as to why. The error i am receiving is below. I understand it is receiving nil when it should be receiving 95 but i still do not understand why. </p>
  
  <pre><code>When They submitted an assignment    # features/step_definitions/teacher_grade_assignment.rb:6
      Then the assignment has a grade      # features/step_definitions/teacher_grade_assignment.rb:14
  
        expected: 95
             got: nil
  
        (compared using ==)
         (RSpec::Expectations::ExpectationNotMetError)
        ./features/step_definitions/teacher_grade_assignment.rb:15:in `/^the assignment has a grade$/'
        features/teacher_can_grade_assignment.feature:11:in `Then the assignment has a grade'
  
  Failing Scenarios:
  cucumber features/teacher_can_grade_assignment.feature:7 # Scenario: Teacher can grade assignment
  </code></pre>
  
  <p><strong>teacher_grade_assignment.rb</strong></p>
  
  <pre><code>Given(/^I have a student$/) do
      @teacher = Teacher.new
      @student = Student.new
  end
  
  Given(/^They submitted an assignment$/) do
    @teacher.submit_assignment(@student, Assignment.new)
  end
  
  When(/^I grade the assignment$/) do
    @teacher.record_grade(@student, 95)
  end
  
  Then(/^the assignment has a grade$/) do
      expect(@teacher.assignment_for_student(@student).grade).to eq(95)
  end
  </code></pre>
  
  <p><strong>student_assignment_steps.rb</strong></p>
  
  <pre><code>Given(/^I am a student$/) do
    @student = Student.new #setting as an instance variable to access later on
    @teacher = Teacher.new
  end
  
  When(/^I submit an assignment to my teacher$/) do
      @assignment = Assignment.new
      @teacher.submit_assignment(@student, @assignment)
  end
  
  Then(/^my teacher should have my assignment$/) do
      expect(@teacher.assignment_for_student(@student)).to eq(@assignment)
  end
  </code></pre>
  
  <p><strong>teacher.rb</strong></p>
  
  <pre><code>class Teacher 
      def initialize
          @assignments = {}
      end
  
      def record_grade(student, grade)
          assignment = @assignments[student] #assignment equal to assignments of the student
          assignment.grade = grade 
          @assignments[student] = assignment
      end 
  
      def submit_assignment(student, assignment)
          @assignments[student] = assignment
      end
  
      def assignment_for_student(student)
          @assignments[student]
      end
  end
  </code></pre>
  
  <p><strong>teacher_spec.rb</strong></p>
  
  <pre><code>require_relative "../lib/teacher"
  require "rspec"
  
  describe Teacher do 
      it "should store assignments" do
          student = double
          assignment = double
          subject.submit_assignment(student, assignment)
          expect(subject.assignment_for_student(student)).to eq(assignment)
      end
  
  describe "should record a grade" do 
      it "should record and the grade" do 
          student = double
          assignment = double
          expect(assignment).to receive(:grade=).with(95)
          subject.submit_assignment(student, assignment)
          subject.record_grade(student, 95)
      end
  end
  end
  </code></pre>
  
  <p><strong>assignment_spec.rb</strong></p>
  
  <pre><code>require_relative "../lib/assignment"
  
  describe Assignment do 
      it "should store a grade" do 
          subject.grade = 60
          expect(subject.grade).to eq(60)
      end 
  end 
  </code></pre>
  
  <p><strong>assignment.rb</strong></p>
  
  <pre><code>class Assignment
      attr_accessor :grade
  end
  </code></pre>
  
  <p><strong>student.rb</strong></p>
  
  <pre><code>class Student
  end
  </code></pre>
  
  <p><strong>teacher_can_grade_assignment.feature</strong></p>
  
  <pre><code>Feature: Teacher can grade assignment
  
      As a Teacher
      I can grade my students' assignments
      So that they can know their knowledge level
  
      Scenario: Teacher can grade assignment
          Given I have a student
          And They submitted an assignment
          When They submitted an assignment
          Then the assignment has a grade
  </code></pre>