Hallo Leute, ich lerne, wie man Code mit RSpec testet, und ich habe diesen Fehler, wenn ich versuche, Rspec auszuführen . Ich denke, ist ein Fehler auf Active Record, aber ich suche googeln und ich habe nicht nichts mir helfen, diese mit ... so mein Fehler ist dies:`method_missing ': undefinierte lokale Variable oder Methode' ture 'für # <Klasse: 0x007f9922f68110> (NameError)
$ rspec
/Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.7.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined local variable or method `ture' for #<Class:0x007f9922f68110> (NameError)
from /Users/romenigld/workspace/ebooks/everyday_rails_Testing_with_RSpec/contact_app/app/models/contact.rb:6:in `<class:Contact>'
from /Users/romenigld/workspace/ebooks/everyday_rails_Testing_with_RSpec/contact_app/app/models/contact.rb:1:in `<top (required)>'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:360:in `require_or_load'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:494:in `load_missing_constant'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/romenigld/workspace/ebooks/everyday_rails_Testing_with_RSpec/contact_app/spec/models/contact_spec.rb:3:in `<top (required)>'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/bin/rspec:22:in `load'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/bin/rspec:22:in `<main>'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `eval'
from /Users/romenigld/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `<main>'
Mein contact_spec.rb
require 'rails_helper'
describe Contact do
it "is valid with a first_name, last_name and email" do
contact = Contact.new(
first_name: 'Aaron',
last_name: 'Sumner',
email: '[email protected]')
expect(contact).to be_valid
end
it "is invalid without a firstname" do
contact = Contact.new(first_name: nil)
contact.valid?
expect(contact.errors[:first_name]).to include("can't be blank")
end
it "is invalid without a lastname" do
contact = Contact.new(last_name: nil)
contact.valid?
expect(contact.errors[:last_name]).to include("can't be blank")
end
it "is invalid without an email address" do
end
it "is invalid with a duplicate email address" do
Contact.create(
first_name: 'Joe',
last_name: 'Tester',
email: '[email protected]'
)
contact = Contact.new(
first_name: 'Jane',
last_name: 'Tester',
email: '[email protected]'
)
contact.valid?
expect(contact.errors[:email]).to include("has already been taken")
end
it "returns a contact's full name as a string" do
contact = Contact.new(
first_name: 'John',
last_name: 'Doe',
email: '[email protected]')
expect(contact.name).to eq 'John Doe'
end
it "returns a sorted array of results taht match" do
smith = Contact.create(
first_name: 'John',
last_name: 'Smith',
email: '[email protected]'
)
jones = Contact.create(
first_name: 'Tim',
last_name: 'Jones',
email: '[email protected]'
)
johnson = Contact.create(
first_name: 'John',
last_name: 'johnson',
email: '[email protected]'
)
expect(Contact.by_letter("J")).to eq [johnson, jones]
end
it "omits results that do not match" do
smith = Contact.create(
first_name: 'John',
last_name: 'Smith',
email: '[email protected]'
)
jones = Contact.create(
first_name: 'Tim',
last_name: 'Jones',
email: '[email protected]'
)
johnson = Contact.create(
first_name: 'John',
last_name: 'Johnson',
email: '[email protected]'
)
expect(Contact.by_letter("J")).not_to include smith
end
end
Mein contact.rb
class Contact < ActiveRecord::Base
has_many :phones
#accepts_nested_attributes_for :phones
validates :first_name, presence: true
validates :last_name, presence: ture
validates :email, presence: true, uniqueness: true
validates :phones, length: { is: 3 }
def name
[first_name, last_name].join('')
end
def self.by_letter(letter)
where("last_name LIKE ?", "#{letter}%").order(:last_name)
end
end
Wenn jemand mir helfen kann, werde ich schätzen!
'Gegenwart: ture' sollte' sein true' – Iceman
Hier ist ein Tipp: wenn Sie etwas tun, ganz normal und sehr Standard, dass Zehntausende von Entwicklern auch jeden Tag mit einem Framework arbeiten, das von Zehntausenden von Entwicklern verwendet wird und Dutzende Millionen Codezeilen davon abhängig ist und irgendwie, * niemand * hat * jemals * bemerkt, dass es einen gibt Fehler, der dieses Framework von Zehntausenden verwendet f Entwickler * völlig nutzlos * ... du liegst falsch. –