未定义的方法混淆

时间:2013-09-06 17:15:41

标签: ruby-on-rails rspec

我是一名研究我的RSpec技能的Rails新手。我遇到了这个未定义的错误,让我挠头。这是:

1) Veiwing the list of movies shows the movies
     Failure/Error: expect(page).to have_text(Movies.location)
     NoMethodError:
       undefined method `location' for #<Class:0x00000104bbb958>
     # ./spec/features/list_movies_spec.rb:26:in `block (2 levels) in <top (required)>

以下是我的spec文件。你能告诉我我在这里俯瞰什么吗?

require "spec_helper"


feature "Veiwing the list of movies" do 
    it "shows the movies" do 

        movie1 = Movies.create(name: "The Butler", location: "New York City",
                                                        price:15.00)
        movie2 = Movies.create(name: "The Grand Master", location: "New Jersey",
                                                        price:15.00)
        movie3 = Movies.create(name: "Elysium", location: "Los Angeles", 
                                                        price:15.00 )
        movie4 = Movies.create(name:"Pacific Rim", location: "Queens NY", 
                                                        price:15.00)


        visit movies_url

        expect(page).to have_text("4 Movies")

        expect(page).to have_text(Movies.name)
        expect(page).to have_text(Movies.name)
        expect(page).to have_text(Movies.name)
        expect(page).to have_text(Movies.name)

        expect(page).to have_text(Movies.location)
        expect(page).to have_text(Movies.description)
        expect(page).to have_text("15.00")


    end

end

1 个答案:

答案 0 :(得分:2)

Movies是一个类,因此没有location的值。您应该针对locationMoviesmovie123的实例检查4。例如:

expect(page).to have_text(movie1.location)