目前,我正努力从Cucumber中找到我的应用程序的助手方法。
我有一个Sinatra应用程序,它具有简单的会话身份验证(通过cookies),我想通过为Cucumber方案添加logged_in?助手方法来切换身份验证。Sinatra和Cucumber在会议上似乎有问题,所以我考虑使用Mocha来解决这个问题。
但是,我不知道如何从一个Sinatra::Application Given-Block中访问该实例,以便对该方法进行存根。
发布于 2009-11-25 23:38:13
您可以使用Sinatra::Application.class_eval获得正确的上下文。
编辑:请参阅海报原件的答案,以获得完整的解释。
发布于 2009-11-26 09:58:21
似乎我需要直接覆盖Before do ... end-block中的身份验证机制
因此,我最终将一个hooks.rb放在features/support/文件中,覆盖了我的logged_in?和current_user方法。
Before do
MySinatraApplicationClass.class_eval do
helpers do
def logged_in?
return true
end
def current_user
# This returns a certain Username usually stored
# in the session, returning it like
# that prohibits different user logins, but for
# now this is enough for me
"Walter"
end
end
end
end我唯一需要注意的是,应用程序中没有其他操作直接从session读取,而是使用这些助手。
可悲的是,我认为这种通过Cucumber处理基于会话的Sinatra应用程序的方式已经在其他地方被描述过了,我只是认为我的问题不一样。
https://stackoverflow.com/questions/1800333
复制相似问题