-1
RoR 튜토리얼을 진행하면서 다음 오류가 발생하여이를 파악하지 못한 것 같습니다. 샘플 코드를 정확하게 복사했지만 내 rspec 테스트가 실행되지 않습니다 (콘솔도 새 사용자를 만들지 않습니다)Rails rspec unexpected tIDENTIFIER
감사합니다, 어떤 도움을 주셔서 감사합니다!
오류 :
[email protected]:~/Ruby/rails_projects/sample_app$ bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
/home/user/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load': /home/user/Ruby/rails_projects/sample_app/spec/models/user_spec.rb:51: syntax error, unexpected tIDENTIFIER, expecting keyword_end (SyntaxError)
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `block in load'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run'
from /home/user/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
여기 내 RSpec에 테스트입니다 : 는 'spec_helper'을 필요로
describe User do
before { @user = User.new(name: "Example User", email: "[email protected]") }
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should be_valid }
describe "when name is not present" do
before { @user.name = " " }
it { should_not be_valid }
end
describe "when name is too long" do
before { @user.name = "a"* 51 }
it { should_not be_valid }
end
describe "when email format is not valid" do
it "should be invalid" do
addresses = %w[[email protected],com user_at_foo.org [email protected]
[email protected]_baz.com [email protected]+baz.com]
addresses.each do |invalid_address|
@user.email = invalid_address
@user.should_not be_valid
end
end
end
describe "when email format is valid" do
it "should be valid" do
addresses = %w[[email protected] [email protected] [email protected] [email protected]]
addresses.each do |valid_address|
@user.email = valid_address|
@user.should be_valid
end
end
end
describe "when email address is already taken" do
before do
user_with_same_email = @user.dup
user_with_same_email.email = @user.email.upcase
user_with_same_email.save
end
it { should_not be_valid }
end
end
그리고 여기 내 사용자 모델이다 :이 줄은 오타가
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
작품! 좋은 캐치, 빠른 답장을 보내 주셔서 감사합니다. – gh0st