LEARN TO CODE+READ SPEC
That takes care of the first part of our error.
An error occurred while loading ./spec/controllers/coupons_controller_spec.rb.
Failure/Error:
describe CouponsController do
describe "POST create" do
context "with valid attributes" do
it "creates a new coupon" do
expect{
post :create, params: { :coupon => { :coupon_code => "ASD123", :store => "Dean and Deluca" } }
}.to change(Coupon,:count).by(1)
end
To break down this line of code..
post :create, params: { :coupon => { :coupon_code => "ASD123", :store => "Dean and Deluca" } }
}.to change(Coupon,:count).by(1)
post = is the request
(:create,) = to create after the request we created
with a params: of { :coupon => { :coupon_code => “ASD123”, :store => “Dean and Deluca” } }
.to change = should change
(Coupon,:count).by(1) the Coupon’s(Coupon Class) Count Method(:count method in our Coupon model) by 1(.by(1)
First Error We run into is “An error occurred while loading ./spec/controllers/coupons_controller_spec.rb.”
and if we check out controller directory we have no Coupon Controller. So we are missing our controller.

To resolve this we simply create a controller using,“rails generate/g controller coupon” or manually with touch app/coupon_controller.rb

Now running “rails g controller coupon” also created other files that we don’t need for this test.
rails g controller coupon

So in order to generate only the files needed for this test lets use
rails g controller coupons --no-test-framework --no-helper --no-assets

And just for the knowledge we can also use “rails g resource coupons — no-test-framework — no-helper — no-assets” which will create our routes.
rails g resource coupons — no-test-framework — no-helper — no-assets


WE RUN OUR TEST AND Receive a New Error!!!