rspec 1:Fixnum 的未定义方法“序列”
rspec undefined method `sequence' for 1:Fixnum
我正在使用 rspec 在 rails 中编写规范测试。我正在测试的模型之一具有 sequence
属性,它与 rspec 冲突(根据我的发现),但我无法找到解决方法。
这是我的代码
lessons.rb(工厂)
FactoryGirl.define do
factory :lesson do
version_id 1
add_attribute :sequence, 1 # this is the field
name "Lesson Name"
description "An Example Lesson Description"
group_id 1
content "here is some example context"
passing_quiz_difficulty 2
survey_id 1
status 1
staff_content "example staff content"
lesson_type_id 1
end
end
我正在测试的方法
def second_response?(lesson)
self.lessons.where('sequence < ?', lesson.sequence).first
end
控制器
def show
...
@part_two = true if @reveal_step.second_response?(@lesson)
...
end
rspec 堆栈跟踪
Failure/Error: expect(@reveal_step.second_response?(lesson_1.id)).to eql true
NoMethodError: undefined method `sequence' for 1:Fixnum
这个方法在应用程序中运行良好,但我需要为它编写一个测试,我找不到使用 sequence
属性的解决方法,我不能将其遗漏,因为整个方法和这部分应用程序的流程取决于 sequence
属性。有谁知道要使用的解决方法?或者我可以用另一种方式来解决这个问题?任何帮助,将不胜感激。
您的期望是将一个数字 lesson_1.id
传递到一个需要上课的方法中。该 ID 没有 sequence
方法,而课程有。
我正在使用 rspec 在 rails 中编写规范测试。我正在测试的模型之一具有 sequence
属性,它与 rspec 冲突(根据我的发现),但我无法找到解决方法。
这是我的代码
lessons.rb(工厂)
FactoryGirl.define do
factory :lesson do
version_id 1
add_attribute :sequence, 1 # this is the field
name "Lesson Name"
description "An Example Lesson Description"
group_id 1
content "here is some example context"
passing_quiz_difficulty 2
survey_id 1
status 1
staff_content "example staff content"
lesson_type_id 1
end
end
我正在测试的方法
def second_response?(lesson)
self.lessons.where('sequence < ?', lesson.sequence).first
end
控制器
def show
...
@part_two = true if @reveal_step.second_response?(@lesson)
...
end
rspec 堆栈跟踪
Failure/Error: expect(@reveal_step.second_response?(lesson_1.id)).to eql true
NoMethodError: undefined method `sequence' for 1:Fixnum
这个方法在应用程序中运行良好,但我需要为它编写一个测试,我找不到使用 sequence
属性的解决方法,我不能将其遗漏,因为整个方法和这部分应用程序的流程取决于 sequence
属性。有谁知道要使用的解决方法?或者我可以用另一种方式来解决这个问题?任何帮助,将不胜感激。
您的期望是将一个数字 lesson_1.id
传递到一个需要上课的方法中。该 ID 没有 sequence
方法,而课程有。