一个小问题我对 Ruby 还很陌生,我有一个包含其他类实例的类(组合)
我正在尝试访问 Cucumber 中的类实例,但不断返回一个错误 undefined method `bk' for nil:NilClass (NoMethodError) 'bk' method is located inside the internal class 我猜这个错误是因为 Cucumber 无法访问内政类。设计这个或合适的解决方案的最佳方法是什么?
class CarConfig
def initialize(browser, wait)
@browser = browser
@wait = wait
@equipments = Equipment.new(@browser)
@interior = Interior.new(@browser)
@engines = Engines.new(@browser)
@exterior = Exterior.new(@browser)
@grades = Grades.new(@browser)
end
def click_comfort
@browser.find_element(:css, 'a.xdata-id-Comfort').click
end
def check_equipment
equipment_availability = []
equipment_not_available = " equipment not available"
equipment_currently_available = "equipment available"
equipment = [@equipments.lifestyle,@equipments.elegance, @equipments.comfort, @equipments.executive, @equipments.luxury,
@equipments.innova].each do
end
equipment_availability.push equipment
if "#{equipment_availability}".include? "disabled"
equipment_not_available
else
equipment_currently_available
end
结尾
Cucumber
Given /^I have selected Comfort$/ do
@car_configurator = CarConfig.new(@browser, @wait)
@browser.get $car_config_page
sleep(2)
@car_configurator.click_comfort
sleep(3)
end
Then /^I should see interior BK as available$/ do
@interior.bk.should_not include ("disabled"), ("selected")
end