Rspec returns syntax error of unexpected '{', expecting keyword_end
In Ruby 2.4.1
not having parens in the let was allowed but in Ruby 2.5.1
it is not.
So the fix is to add parens to the let
, e.g.
change
let :source {'cba321'}
to
let (:source) {'cba321'}
rspec: failure/error: _send_(method, file). syntaxError: 104: syntax error, unexpected keyword_end, expecting end-of-input
I think you have missed do
in the first line RSpec.describe GramsController, type: :controller
. Find below the edited code. Hope this helps!
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
Syntax error syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
It seems that you have a bunch of describe
s that never have end
s keywords, starting with describe "when email format is invalid" do
until describe "when email address is already taken" do
Put an end on those guys and you're probably done =)
Rspec let hash key unexpected =, expecting '}'
- If your block spans for more than one line use
do
/end
. When above is done you'll see that you're missing both the opening
{
and closing}
of the hash:let(:wrong_question1) do
{
"id" => 1,
"description" => "test 3",
"difficulty" => { "id" => 1, "description" => "easy" }
}
end
Heroku run rake db:seed gives expecting keyword_end
The "expected keyword_end" error means you have a syntax error in the specified file. You'll see this a lot, especially in your test suite; get cozy with it.
Go through the file with a fine-tooth comb and mentally match up each {
with its }
and each do
with its end
. Usually you discover that one of these is mismatched.
If you can't find the mismatch, comment out your entire seed file and run rake db:seed
again. The error should not appear. Then progressively uncomment each section of the file until you figure out where the error comes from.
This is tedious but it works.
Chef recipe: syntax error,unexpected tIDENTIFIER, expecting ':'
Solved it my self
off course @Codrenger's answer gave me direction. Thanks
default['zookeeper']['cluster_ips'] = {'1.1.1.1' => 1, '2.2.2.2' => 2}
.
.
.
node['zookeeper']['cluster_ips'].each do |ip, id|
if node["ipaddress"] == ip
template "#{zookeeper_data}/myid" do
source "myid.erb"
owner zookeeper_user
group zookeeper_user
variables myid: id
end
end
end
Related Topics
Count Overlapping Regex Matches in Perl or Ruby
Is It a Bad Idea Do Divide the Models into Directories
Create a Ruby Method That Accepts a Hash of Parameters
Rails Byebug Did Not Stop Application
Download All Gems Dependencies
Shoulda/Rspec Matchers - Conditional Validation
Difference Between Block and &Block in Ruby
Gracefully Shutting Down Sidekiq Processes
Get File Name and Extension in Ruby
Capistrano Deploy Fails After I Changed the Repository Url
Sorting an Array of Objects in Ruby by Object Attribute
Should I Specify Exact Versions in My Gemfile
Why Would We Put a Module Inside a Class in Ruby
Intermingling Attr_Accessor and an Initialize Method in One Class
Does Ruby Provide a Constant_Added Hook Method
Randomly Showing Nomethoderror: Undefined Method 'Empty' for 0:Fixnum