0

我定义了一个课程>>级别>>和工厂女孩的步骤。Step 属于 level , level 属于 course (它们每个都有一个 has_many 关系)。

这是错误(我什至不知道从哪里开始):

Failure/Error: before { visit course_level_step_path(course.id, level.id, step.id)}
 ActionView::Template::Error:
   0x003fe5daf528a0 is not id value

这是我需要的路线:

 course_level_step GET        /courses/:course_id/levels/:level_id/steps/:id(.:format) steps#show

这是我的rspec:

    describe "attempting a step" do
        let(:course) { FactoryGirl.create(:course)}
        let(:level) { FactoryGirl.create(:level)}
        let(:step) { FactoryGirl.create(:step)}
        before { sign_in user}

        describe "taking a course" do
            before { visit course_level_step_path(course.id, level.id, step.id)}  <<< here is the problem

            it "should increment the user step count" do
                expect do
                    click_button "check answer"
                end.to change(user.user_steps, :count).by(1)
            end

            describe "toggling the button" do
                before { click_button "check answer"}
                it {  should have_selector('input', value: 'remove step')}
            end

        end

这是我的工厂:

FactoryGirl.define do
      factory :user do
        sequence(:name)  { |n| "Person #{n}" }
        sequence(:email) { |n| "person_#{n}@example.com" }
        password "foobar"
        password_confirmation "foobar"

        factory :admin do
            admin true
        end
      end

      factory :course do
        sequence(:title) { |n| "Ze Finance Course #{n}" }
        sequence(:description) { |n| "Description for course #{n}" }
      end

      factory :level do
        course
        sequence(:title) { |n| "Ze Finance Level #{n}" }
      end

      factory :step do
        level
        sequence(:description) { |n| "Description for course #{n}" }
      end
end

任何有关错误以及如何解决它的指导将不胜感激。

4

1 回答 1

0

您的错误似乎来自视图。你能发布代码和控制器吗?也为您以后省去更多麻烦:这条线

before { visit course_level_step_path(course.id, level.id, step.id) } 

由于 Factory Girl 的工作方式,创建了一个步骤、两个级别和三个课程。你可能想重写你的两个 let 子句

let(:level) { FactoryGirl.create(:level, course: course) }
let(:step) { FactoryGirl.create(:step, level: level) }
于 2013-10-11T23:25:29.763 回答