hashrocket / decent_exposure

A helper for creating declarative interfaces in controllers
MIT License
1.81k stars 107 forks source link

Helper rspec test issue. #154

Closed RajnikRadadiya closed 8 years ago

RajnikRadadiya commented 8 years ago

I am test my helper.

helper method use account object created from controller by expose.

when i am test. assign(:account, account)

That is no assign to account object which is we have assigned.

that will assign @account.

vnegrisolo commented 8 years ago

hey @Rajniktc this assigns(:account, account) does not work because decentexposure uses an instance variable like `"exposed#{name}", in this case::exposed_account` would work.

Perhaps, the main point of decent_exposure is to do not use instance variables in views/helpers, so I would avoid that on your tests too. So I would change assigns(:account, account) to expect(controller.account).to eq(account)

For example, in our integration tests we are using the method call directly controller.bird to assert the assigned value.

  it "builds bird if id is not provided" do
    bird = double("Bird")
    expect(Bird).to receive(:new).with({}).and_return(bird)
    get :show
    expect(controller.bird).to eq(bird)
  end

Closing this issue for now.