克隆最新稳定版本后
- rails (2.3.2),
- rspec (1.2.2),
- cucumber (0.2.0.4...2009-03-24 发布),
- rspec-rails (1.2.2),
- restful-authentication (修复了 formatted_user_path 和其他一些问题),
- webrat ,
- rubyist-aasm (以及其他一些)
进入一个干净的rails应用程序,并遵循(我认为是)每个插件的所有说明, cucumber 故事仍然失败:-(。以下是问题的摘要:
- 尽管创建了 'map.root :controller => "my_controller"' 路线,但重定向并未立即生效:
expected redirect to "/", got no redirect (Spec::Expectations::ExpectationNotMetError) /cygdrive/c/development/test/vendor/plugins/rspec/lib/spec/expectations.rb:57:in `fail_with' /cygdrive/c/development/test/vendor/plugins/rspec/lib/spec/expectations/handler.rb:14:in `handle_matcher' /cygdrive/c/development/test/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb:31:in `should'. /features/step_definitions/user_steps.rb:111:in `/^an? (.*) user named '(.*)'$/' features/sessions.feature:25:in `And an activated user named 'reggie''
- 故事说,尽管
features/step_definitions/ra_env.rb
文件调用,但logged_in?
方法仍受到保护:ApplicationController.send(:public, :logged\_in?, :current\_user, :authorized?)
该调用是否无需 stub 即可使这些方法可用?
哦,我正在尝试运行 autospec,因此我执行了以下命令来启动它:
export AUTOFEATURE=true rake spec:server:start ruby script/autospec
最佳答案
我做了一些研究,这就是我得到的结果。 ra_response_steps.rb 期望重定向是粗略的,然后用故事来定义是否应该遵循重定向。 这是失败的,因为 Webrat Session 实现具有以下代码:
def request_page(url, http_method, data) #:nodoc: h = headers h['HTTP_REFERER'] = @current_url if @current_url debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect} and HTTP headers #{h.inspect}" if h.empty? send "#{http_method}", url, data || {} else send "#{http_method}", url, data || {}, h end save_and_open_page if exception_caught? && Webrat.configuration.open_error_files? raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code? reset @current_url = url @http_method = http_method @data = data if internal_redirect? check_for_infinite_redirects request_page(response_location, :get, {}) end return response end
注意ifinternal_redirect? ...结束
。这是导致我们测试失败的原因,因为 webrat 正在遵循重定向。
作为解决方法,您可以在 webrat session 中评论这些行,但这可能不是一个不错的解决方案。我会多做一点工作并在某个地方发布补丁。
关于ruby-on-rails - 如何让故事与 Restful 身份验证和 cucumber 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/679928/