rspec:失败/错误:_send_(方法,文件)。语法错误:104:语法错误,意外的keyword_end,预期输入结束

布罗林

在终端窗口中执行bundle exec rspec之后。我收到两个错误:[失败/错误:发送(方法,文件)和语法错误:/vagrant/src/grammable/spec/controllers/grams_controller_spec.rb:104:语法错误,意外的keyword_end,期望输入结束] 。由于范例外发生1个错误,因此我无法通过测试。

require 'rails_helper'

RSpec.describe GramsController, type: :controller 
    describe "grams#update action" do
        it "should allow users to successfully update grams" do
            gram = FactoryBot.create(:gram, message: "Initial Value")
            patch :update, params: { id: gram.id, gram: { message: 'Changed' } }
            expect(response).to redirect_to root_path
            gram.reload
            expect(gram.message).to eq "Changed"
        end

        it "should have http 404 error if the gram cannot be found" do
            patch :update, params: { id: "YOLOSWAG", gram: { message: 'Changed' } }
            expect(response).to have_http_status(:not_found)
        end

        it "should render the edit form with an http status of unprocessable_entity" do
            gram = FactoryBot.create(:gram, message: "Initial Value")
            patch :update, params: { id: gram.id, gram: { message: '' } }
            expect(response).to have_http_status(:unprocessable_entity)
            gram.reload
            expect(gram.message).to eq "Initial Value"
        end
    end

    describe "grams#edit action" do
        it "should successfully show the edit form if the gram is found" do
            gram = FactoryBot.create(:gram)
            get :edit, params: { id: gram.id }
            expect(response).to have_http_status(:success)
        end

        it "should return a 404 error message if the gram is not found" do
            get :edit, params: { id: 'SWAG' }
            expect(response).to have_http_status(:not_found)
        end
    end

    describe "grams#show action" do
        it "should successfully show the page if the gram is found" do
            gram = FactoryBot.create(:gram)
            get :show, params: { id: gram.id }
            expect(response).to have_http_status(:success)
        end

        it "should return a 404 error if the gram is not found" do
            get :show, params: { id: 'TACOCAT' }
            expect(response).to have_http_status(:not_found)
        end
    end

    describe "grams#index action" do
        it "should successfully show the page" do
            get :index
            expect(response).to have_http_status(:success)
        end 
    end

    describe "grams#new action" do

        it "should require users to be logged in" do
            get :new
            expect(response).to redirect_to new_user_session_path
        end

        it "should successfully show the new form" do
            user = FactoryBot.create(:user)
            sign_in user

            get :new
            expect(response).to have_http_status(:success)
        end
    end

    describe "grams#create action" do

        it "should require users to be logged in" do
            post :create, params: { gram: { message: "Hello" } }
            expect(response).to redirect_to new_user_session_path
        end

        it "should successfully create a new gram in our database" do
            user = FactoryBot.create(:user)
            sign_in user

            post :create, params: { gram: { message: 'Hello!' } }
            expect(response).to redirect_to root_path

            gram = Gram.last
            expect(gram.message).to eq("Hello!")
            expect(gram.user).to eq(user)
        end

        it "should properly deal with validation errors" do
            user = FactoryBot.create(:user)
            sign_in user

            post :create, params: { gram: { message: '' } }
            expect(response).to have_http_status(:unprocessable_entity)
            expect(Gram.count).to eq Gram.count
        end
    end
end
Prasath Rajasekaran

我想你错过do了第一行RSpec.describe GramsController, type: :controller在编辑后的代码下方找到。希望这可以帮助!

require 'rails_helper'

RSpec.describe GramsController, type: :controller do
    describe "grams#update action" do
        it "should allow users to successfully update grams" do
            gram = FactoryBot.create(:gram, message: "Initial Value")
            patch :update, params: { id: gram.id, gram: { message: 'Changed' } }
            expect(response).to redirect_to root_path
            gram.reload
            expect(gram.message).to eq "Changed"
        end

        it "should have http 404 error if the gram cannot be found" do
            patch :update, params: { id: "YOLOSWAG", gram: { message: 'Changed' } }
            expect(response).to have_http_status(:not_found)
        end

        it "should render the edit form with an http status of unprocessable_entity" do
            gram = FactoryBot.create(:gram, message: "Initial Value")
            patch :update, params: { id: gram.id, gram: { message: '' } }
            expect(response).to have_http_status(:unprocessable_entity)
            gram.reload
            expect(gram.message).to eq "Initial Value"
        end
    end

    describe "grams#edit action" do
        it "should successfully show the edit form if the gram is found" do
            gram = FactoryBot.create(:gram)
            get :edit, params: { id: gram.id }
            expect(response).to have_http_status(:success)
        end

        it "should return a 404 error message if the gram is not found" do
            get :edit, params: { id: 'SWAG' }
            expect(response).to have_http_status(:not_found)
        end
    end

    describe "grams#show action" do
        it "should successfully show the page if the gram is found" do
            gram = FactoryBot.create(:gram)
            get :show, params: { id: gram.id }
            expect(response).to have_http_status(:success)
        end

        it "should return a 404 error if the gram is not found" do
            get :show, params: { id: 'TACOCAT' }
            expect(response).to have_http_status(:not_found)
        end
    end

    describe "grams#index action" do
        it "should successfully show the page" do
            get :index
            expect(response).to have_http_status(:success)
        end 
    end

    describe "grams#new action" do

        it "should require users to be logged in" do
            get :new
            expect(response).to redirect_to new_user_session_path
        end

        it "should successfully show the new form" do
            user = FactoryBot.create(:user)
            sign_in user

            get :new
            expect(response).to have_http_status(:success)
        end
    end

    describe "grams#create action" do

        it "should require users to be logged in" do
            post :create, params: { gram: { message: "Hello" } }
            expect(response).to redirect_to new_user_session_path
        end

        it "should successfully create a new gram in our database" do
            user = FactoryBot.create(:user)
            sign_in user

            post :create, params: { gram: { message: 'Hello!' } }
            expect(response).to redirect_to root_path

            gram = Gram.last
            expect(gram.message).to eq("Hello!")
            expect(gram.user).to eq(user)
        end

        it "should properly deal with validation errors" do
            user = FactoryBot.create(:user)
            sign_in user

            post :create, params: { gram: { message: '' } }
            expect(response).to have_http_status(:unprocessable_entity)
            expect(Gram.count).to eq Gram.count
        end
    end
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档