rspec main theme

 ...................................................................................................................

    #   it "when tax not found" do

    #   @tax.destroy

    #   get TAX_URL + "#{@tax.id}", headers: @headers

    #   json_data = json_response(response)

    #   expect(json_data["errors"]).to eq nil

    #   expect(response).to have_http_status 404

    # end

 ...................................................................................................................

1. first give url -    

get TAX_URL + "#{@tax.id}", headers: @headers

with our without id  - request goes through this 

with id  ---   get TAX_URL + "#{@tax.id}", headers: @headers

without id ---  get TAX_URL , headers: @headers

2. after this take the response --- 

 json_data = json_response(response)

3. after that compare the error if any error is there -- 

expect(json_data["errors"]).to eq nil   OR 

expect(json_data["errors"]['name'].join("")).to eq "name can't be blank"

4. after that you compare the response ---  

      expect(response).to have_http_status 201
          expect(response).to have_http_status 404
      expect(response.status).to eq 200

5.can compare the json data with the id ----- 

      expect(json_data['data']['id'].to_i).to eq @tax.id

..................................................................................................................................

note --   check these terms
response 
response.status    -- get the status code by this 

 ...................................................................................................................

note - controller se front end ka kam bhi ho raha hai so controller mein change nai karna hai 
sirf rspec mein hi changes karne hain .

 ...................................................................................................................

 ...................................................................................................................

errors ::::

1.
      expect(json_data["errors"]).to eq nil
  ---------------------------  agar koi error na ho tab isko lagate hein 

2. 

    




Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5