Reputation: 2681
I am following http://goo.gl/7Dlv5.The video creates a class
class Book
end
The test spec/book_spec.rb looks like:
require "spec_helper"
describe Book do
before :each do
@book = Book.new "Title","Author", :category
end
describe "#new" do
it "returns a new book object" do
@book.should be_an_instance_of Book
end
end
end
The test passes for the author. It fails for me. So I guess something changed in ruby? Or maybe a typo I am not able to find in my code. Can you please help?
This is my result. Thank you.
Failures:
1) Book#new returns a new book object
Failure/Error: @book = Book.new "Title","Author", :category
ArgumentError:
wrong number of arguments(3 for 0)
# ./spec/book_spec.rb:6:in `initialize'
# ./spec/book_spec.rb:6:in `new'
# ./spec/book_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.00058 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/book_spec.rb:11 # Book#new returns a new book object
Upvotes: 0
Views: 695
Reputation: 121010
That’s clear that you are to define a respective constructor for Book
class to call Book.new
with three args.
The link above clearly says that (look at the text transcript):
# These will fail, so here’s the code for Book to make them pass:
class Book
attr_accessor :title, :author, :category
def initialize title, author, category
@title = title
@author = author
@category = category
end
end
Upvotes: 1