【发布时间】:2014-02-28 05:50:44
【问题描述】:
通常我会避免控制器测试并坚持使用 Model & Cucumber,但我发现自己需要一个,但我似乎无法动起来。
下面的代码太简单了..我几乎把所有东西都删掉了
1 require 'spec_helper'
2
3 describe ExperiencesController do
4 describe "GET #show" do
5 context "experience item" do
6 it "redirects to the success url" do
7 experience = build(:experience)
8 get :show, :id => experience.id
9 #should be a test here :)
10 end
11 end
12 end
13 end
产生以下结果
Failures:
1) ExperiencesController GET #show experience item redirects to the success url
Failure/Error: get :show, :id => experience.id
NoMethodError:
undefined method `id' for Sinatra::Application:Class
# (__DELEGATE__):2:in `get'
# ./spec/controller_spec/experiences_controller_spec.rb:8:in `block (4 levels) in <top (required)>'
$ rake routes|grep experience
experiences GET /experiences(.:format) experiences#index
POST /experiences(.:format) experiences#create
new_experience GET /experiences/new(.:format) experiences#new
edit_experience GET /experiences/:id/edit(.:format) experiences#edit
experience GET /experiences/:id(.:format) experiences#show
PUT /experiences/:id(.:format) experiences#update
DELETE /experiences/:id(.:format) experiences#destroy
真的感觉像是一种配置类型的东西 我不明白为什么会产生 Sinatra 错误 任何帮助表示赞赏
** 更新**
SideKiq 及其依赖项 sinatra 安装在此 rails 应用程序的 Gemfile 中。 而且我相信 sinatra 可能会干扰控制器测试。
【问题讨论】:
标签: ruby-on-rails testing rspec controller mocha.js