I have just begun chapter 10, gone through just after the Figure 10.1.
I have tried rake db:reset before my migrate and test:prepare commands, but that has not worked.
Here is my error, I could not find a similar one on here:
Failures:
1) Micropost
Failure/Error: @micropost = Micropost.new(content: "Lorem ipsum", user_id: user_id)
NameError:
undefined local variable or method `user_id' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fcfecc789b8>
# ./spec/models/micropost_spec.rb:9:in `block (2 levels) in <top (required)>'
2) Micropost
Failure/Error: @micropost = Micropost.new(content: "Lorem ipsum", user_id: user_id)
NameError:
undefined local variable or method `user_id' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fcfecc8a000>
# ./spec/models/micropost_spec.rb:9:in `block (2 levels) in <top (required)>'
Finished in 0.00389 seconds
2 examples, 2 failures
Failed examples:
rspec ./spec/models/micropost_spec.rb:15 # Micropost
rspec ./spec/models/micropost_spec.rb:14 # Micropost
Here is my code:
for the file: db/migrate/[my unique timestamp]_create_microposts.rb
class CreateMicroposts < ActiveRecord::Migration
def change
create_table :microposts do |t|
t.string :content
t.integer :user_id
t.timestamps
end
add_index :microposts, [:user_id, :created_at]
end
end
For file: spec/models/micropost_spec.rb
require 'spec_helper'
describe Micropost do
# pending "add some examples to (or delete) #{__FILE__}"
let(:user) { FactoryGirl.create(:user) }
before do
#This code is not correct, idiomatically
@micropost = Micropost.new(content: "Lorem ipsum", user_id: user_id)
end
subject { @micropost }
it { should respond_to(:content) }
it { should respond_to(:user_id) }
end
PS all my tests were green going into ch. 10