I'm getting the following 3 errors for my code in the micropost_spec.rb file. How would I fix them? I think I'm following the tutorial exactly but it may be a problem with differing versions of Rails.
Ruby version: 1.9.2p320
Rails version: 3.2.13
Rspec: 2.11.1
Computer: Macbook pro OS X Mountain Lion
Errors
1) Micropost when user_id is not present
Failure/Error: it { User.should_not be_valid }
NoMethodError:
undefined method `valid?' for #
# ./spec/models/micropost_spec.rb:19:in `block (3 levels) in '
2) Micropost with blank content
Failure/Error: it { User.should_not be_valid}
NoMethodError:
undefined method `valid?' for #
# ./spec/models/micropost_spec.rb:24:in `block (3 levels) in '
3) Micropost when content is too long
Failure/Error: it { User.should_not be_valid }
NoMethodError:
undefined method `valid?' for #
# ./spec/models/micropost_spec.rb:29:in `block (3 levels) in '
micropost_spec.rb
require 'spec_helper'
describe Micropost do
let(:user) { FactoryGirl.create(:user) }
before { @micropost = user.microposts.build(content: "Lorem ipsum") }
subject { @micropost }
it { should respond_to(:content) }
it { should respond_to(:user_id) }
it { should respond_to(:user) }
its(:user) { should eq user }
it { should be_valid }
describe "when user_id is not present" do
before { @micropost.user_id = nil }
it { should_not be_valid }
end
describe "with blank content" do
before { @micropost = " "}
it { should_not be_valid}
end
describe "when content is too long" do
before { @micropost = "a" * 141 }
it { should_not be_valid }
end
end
@micropost = "a" * 141etc are not correct; you should be modifying a property of theMicropost, not setting the value of@micropost. But your test subject is wrong, for some reason. - Dave Newtonuserinstead ofUser? - scaryguy@micropost = ...issue, edit your question to reflect the current content. Post the version of Ruby, Rails, RSpec at least. - Dave Newton@micropost.content = "a" * 141. If you search for the text you have, it does not appear. - Peter Alfvin