我用rspec编写了一个控件测试:
def index
@books = Book.all.order("created_at DESC")
end
books_controller.rb
FactoryGirl.define do
factory :book do |f|
f.name { Faker::Book.title }
f.author { Faker::Book.author }
f.press { Faker::Book.publisher }
f.cover { fixture_file_upload(Rails.root.join('spec', 'photos', 'testcover.jpg'), 'image/png') }
end
end
books.rb
1) BooksController GET #index populates an array of books
Failure/Error: expect(:books).to eql([book])
expected: [#<Book id: 1, name: "The Waste Land", author: "谢靖琪", isbn: nil, press: "University of Chicago Press"...e: "image/png", cover_file_size: 104531, cover_updated_at: "2016-08-26 04:00:19", page_number: nil>]
got: :books
(compared using eql?)
Diff:
@@ -1,2 +1,2 @@
-[#<Book id: 1, name: "The Waste Land", author: "谢靖琪", isbn: nil, press: "University of Chicago Press", description: nil, grade_level: nil, lexile_level: nil, douban_link: nil, scholastic_link: nil, created_at: "2016-08-26 04:00:19", updated_at: "2016-08-26 04:00:19", cover_file_name: "fcbcb7417dbc88827d16765a.jpg", cover_content_type: "image/png", cover_file_size: 104531, cover_updated_at: "2016-08-26 04:00:19", page_number: nil>]
+:books
运行bin / rake规范,结果是:
var cost_value= 7777;
console.log(typeof(cost_value));
if (String(typeof(cost_value)) !== "number") {
alert("not a number");//7777
} else {
alert("a number");
}
他们并不平等。似乎第一个预期的结果,'...'是缩写。我该如何解决?
答案 0 :(得分:3)
我认为你想要的是
expect(assigns(:books)).to eq([book])