0

My controller and my test file are bellow.

controllers/reports_controller.rb:

def index
    @reports = Report.all
  end

specs/controllers/reports_controller_spec.rb:

RSpec.describe ReportsController, type: :controller do
  let(:test_report) {
    2.times.map {
      create(:report, student: create(:student), report_options_attributes: [
        {option: create(:option), note: "ole" }
      ])
    }
  }

  describe "GET #index" do
    before(:each) do
      get :index
    end

    it "should be success" do
      expect(response).to be_success
    end

    it "should render index template" do
      expect(response).to render_template(:index)
    end

    it "should load all reports" do
      expect(assigns(:report)).to match_array test_report
    end
  end

The last test is not working, but it should work. What is wrong with it?

2 Answers 2

2

index test is empty..you need to assert something to pass.

can you add.. assert_response :success in index function.

Sign up to request clarification or add additional context in comments.

1 Comment

The first two tests are passing. Just the last one is not.
0

Your var is different from the controller. Use reports instead of report like this:

it "should load all reports" do
      expect(assigns(:reports)).to match_array test_report
    end

It should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.