0

Hi I am learning to write test cases with Rspec in ruby and am following this link. So while testing the following case

 require 'spec_helper'

describe "Library object" do
before :all do
    lib_obj = [
        Book.new ("Javascript: The Good Parts", "Douglas Crockford", :development),
        Book.new ("Designing with Web Standards", "Jeffrey Zeldman", :design),
        Book.new ("Don't make me Think", "Steve krug", :usability),
        Book.new ("Javascript Patterns", "Stoyam Stefanov", :development),
        Book.new ("Responsive Web Design", "Ethan Marcotte", :design)
    ]       
    File.open "books.yml", "w" do |f|
        f.write YAML::dump lib_obj
    end
end

before :each do
    @lib = Library.new "books.yml"
end

describe "#new" do
    context "with no parameters" do
        it "has no books" do
            lib = Library.new
            lib.should have(0).books
        end
    end
    context "with a yaml file paramater" do
        it "has five books" do
            @lib.should have(5).books
        end
    end
end

it "returns all the books in a given category" do
    @lib.get_books_in_category(:development).length.should == 2
end

it "accepts new books" do
    @lib.add_book(Book.new("Designing for the Web", "Mark Boulton", :design))
    @lib.get_book("Designing for the Web").should be_an_instance_of Book
end

it "saves the library" do
    books = @lib.books.map { |book| book.title  }
    @lib.save
    lib2 = Library.new "books.yml"
    books2 = lib2.books.map { |book| book.title  }
    books.should eql books2
end

end

I am getting the following error:-

syntax error, unexpected ',', expecting keyword_end
 Book.new ("Don't make me Think", "Steve krug", :usability),

This stands for all the entries in array lib_obj. I am using ruby 1.9.3 and rails 3.2.6

Kindly help

0

2 Answers 2

3

You have an extra space between your method calls and argument lists.

Book.new (...)

...is not the same as:

Book.new(...)
Sign up to request clarification or add additional context in comments.

Comments

2

I see you are passing in string value's for a new Book class although you are not specifying the attribute you want to bind it to.

try:

new_book = Book.new(:name => "string", :cover_image => "string") etc.

also make sure your model validations and mass_assignment security are set correctly but your test will point you there soon.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.