私は RoR チュートリアルを進めていますが、次のエラーに遭遇し、それを理解できないようです。サンプル コードを正確にコピーしましたが、rspec テストはまだ実行されません (コンソールで新しいユーザーを作成することさえできません)。
助けてくれてありがとう、ありがとう!
エラー:
user@ubuntu:~/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 テストです: require 'spec_helper'
describe User do
before { @user = User.new(name: "Example User", email: "user@example.com") }
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[user@foo,com user_at_foo.org example.user@foo.
foo@bar_baz.com foo@bar+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[user@foo.com A_US-ER@f.b.org first.last@foo.jp a+b@baz.cn]
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+\-.]+@[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