2012-04-17 62 views
1

我正在寫一個回報率的應用程序,並自動生成測試失敗,因爲以下內容:RSpec的找不到HAML文件

11) Sources GET /sources works! (now write some real specs) 
    Failure/Error: get sources_path 
    ActionView::MissingTemplate: 
     Missing template sources/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: 
     * "/Users/brian.hicks/Dropbox/code/incremental/incremental/app/views" 
     * "/Users/brian.hicks/.rvm/gems/[email protected]/gems/devise-2.0.4/app/views" 
    # ./app/controllers/sources_controller.rb:11:in `index' 
    # ./spec/requests/sources_spec.rb:7:in `block (3 levels) in <top (required)>' 

我用我的Gemfile如下:

gem 'rails', '3.2.3' 
gem 'haml-rails', '>= 0.3.4' 
gem 'rspec-rail', '>= 2.8.1' 

是否有一個特定的配置值,我需要設置某處以使用:haml處理程序以及其餘的處理程序?

按要求,這裏是Gemfile.lock

GEM 
    remote: https://rubygems.org/ 
    specs: 
    actionmailer (3.2.3) 
     actionpack (= 3.2.3) 
     mail (~> 2.4.4) 
    actionpack (3.2.3) 
     activemodel (= 3.2.3) 
     activesupport (= 3.2.3) 
     builder (~> 3.0.0) 
     erubis (~> 2.7.0) 
     journey (~> 1.0.1) 
     rack (~> 1.4.0) 
     rack-cache (~> 1.2) 
     rack-test (~> 0.6.1) 
     sprockets (~> 2.1.2) 
    activemodel (3.2.3) 
     activesupport (= 3.2.3) 
     builder (~> 3.0.0) 
    activerecord (3.2.3) 
     activemodel (= 3.2.3) 
     activesupport (= 3.2.3) 
     arel (~> 3.0.2) 
     tzinfo (~> 0.3.29) 
    activeresource (3.2.3) 
     activemodel (= 3.2.3) 
     activesupport (= 3.2.3) 
    activesupport (3.2.3) 
     i18n (~> 0.6) 
     multi_json (~> 1.0) 
    addressable (2.2.7) 
    arel (3.0.2) 
    bcrypt-ruby (3.0.1) 
    bson (1.6.2) 
    bson_ext (1.6.2) 
     bson (~> 1.6.2) 
    builder (3.0.0) 
    cancan (1.6.7) 
    capybara (1.1.2) 
     mime-types (>= 1.16) 
     nokogiri (>= 1.3.3) 
     rack (>= 1.0.0) 
     rack-test (>= 0.5.4) 
     selenium-webdriver (~> 2.0) 
     xpath (~> 0.1.4) 
    childprocess (0.3.1) 
     ffi (~> 1.0.6) 
    coffee-rails (3.2.2) 
     coffee-script (>= 2.2.0) 
     railties (~> 3.2.0) 
    coffee-script (2.2.0) 
     coffee-script-source 
     execjs 
    coffee-script-source (1.3.1) 
    daemons (1.1.8) 
    database_cleaner (0.7.2) 
    devise (2.0.4) 
     bcrypt-ruby (~> 3.0) 
     orm_adapter (~> 0.0.3) 
     railties (~> 3.1) 
     warden (~> 1.1.1) 
    diff-lcs (1.1.3) 
    erubis (2.7.0) 
    eventmachine (0.12.10) 
    execjs (1.3.0) 
     multi_json (~> 1.0) 
    factory_girl (3.1.0) 
     activesupport (>= 3.0.0) 
    factory_girl_rails (3.1.0) 
     factory_girl (~> 3.1.0) 
     railties (>= 3.0.0) 
    ffi (1.0.11) 
    haml (3.1.4) 
    haml-rails (0.3.4) 
     actionpack (~> 3.0) 
     activesupport (~> 3.0) 
     haml (~> 3.0) 
     railties (~> 3.0) 
    heroku (2.24.1) 
     launchy (>= 0.3.2) 
     netrc (~> 0.7.1) 
     rest-client (~> 1.6.1) 
     rubyzip 
    hike (1.2.1) 
    i18n (0.6.0) 
    journey (1.0.3) 
    jquery-rails (2.0.2) 
     railties (>= 3.2.0, < 5.0) 
     thor (~> 0.14) 
    json (1.6.6) 
    launchy (2.1.0) 
     addressable (~> 2.2.6) 
    libwebsocket (0.1.3) 
     addressable 
    mail (2.4.4) 
     i18n (>= 0.4.0) 
     mime-types (~> 1.16) 
     treetop (~> 1.4.8) 
    mime-types (1.18) 
    mongo (1.6.2) 
     bson (~> 1.6.2) 
    mongoid (2.4.8) 
     activemodel (~> 3.1) 
     mongo (~> 1.3) 
     tzinfo (~> 0.3.22) 
    mongoid-rspec (1.4.4) 
     mongoid (~> 2.0) 
     rspec (~> 2) 
    multi_json (1.2.0) 
    netrc (0.7.1) 
    nokogiri (1.5.2) 
    orm_adapter (0.0.7) 
    polyglot (0.3.3) 
    quiet_assets (1.0.0) 
     rails (~> 3.1) 
    rack (1.4.1) 
    rack-cache (1.2) 
     rack (>= 0.4) 
    rack-ssl (1.3.2) 
     rack 
    rack-test (0.6.1) 
     rack (>= 1.0) 
    rails (3.2.3) 
     actionmailer (= 3.2.3) 
     actionpack (= 3.2.3) 
     activerecord (= 3.2.3) 
     activeresource (= 3.2.3) 
     activesupport (= 3.2.3) 
     bundler (~> 1.0) 
     railties (= 3.2.3) 
    railties (3.2.3) 
     actionpack (= 3.2.3) 
     activesupport (= 3.2.3) 
     rack-ssl (~> 1.3.2) 
     rake (>= 0.8.7) 
     rdoc (~> 3.4) 
     thor (~> 0.14.6) 
    rake (0.9.2.2) 
    rdoc (3.12) 
     json (~> 1.4) 
    rest-client (1.6.7) 
     mime-types (>= 1.16) 
    rspec (2.9.0) 
     rspec-core (~> 2.9.0) 
     rspec-expectations (~> 2.9.0) 
     rspec-mocks (~> 2.9.0) 
    rspec-core (2.9.0) 
    rspec-expectations (2.9.1) 
     diff-lcs (~> 1.1.3) 
    rspec-mocks (2.9.0) 
    rspec-rails (2.9.0) 
     actionpack (>= 3.0) 
     activesupport (>= 3.0) 
     railties (>= 3.0) 
     rspec (~> 2.9.0) 
    rubyzip (0.9.7) 
    sass (3.1.15) 
    sass-rails (3.2.5) 
     railties (~> 3.2.0) 
     sass (>= 3.1.10) 
     tilt (~> 1.3) 
    selenium-webdriver (2.21.0) 
     childprocess (>= 0.2.5) 
     ffi (~> 1.0) 
     libwebsocket (~> 0.1.3) 
     multi_json (~> 1.0) 
     rubyzip 
    simple_form (2.0.1) 
     actionpack (~> 3.0) 
     activemodel (~> 3.0) 
    sprockets (2.1.2) 
     hike (~> 1.2) 
     rack (~> 1.0) 
     tilt (~> 1.1, != 1.3.0) 
    thin (1.3.1) 
     daemons (>= 1.0.9) 
     eventmachine (>= 0.12.6) 
     rack (>= 1.0.0) 
    thor (0.14.6) 
    tilt (1.3.3) 
    treetop (1.4.10) 
     polyglot 
     polyglot (>= 0.3.1) 
    tzinfo (0.3.33) 
    uglifier (1.2.4) 
     execjs (>= 0.3.0) 
     multi_json (>= 1.0.2) 
    warden (1.1.1) 
     rack (>= 1.0) 
    xpath (0.1.4) 
     nokogiri (~> 1.3) 

PLATFORMS 
    ruby 

DEPENDENCIES 
    bson_ext (>= 1.3.1) 
    cancan 
    capybara (>= 1.1.2) 
    coffee-rails (~> 3.2.1) 
    database_cleaner (>= 0.7.1) 
    devise (>= 2.0.0) 
    factory_girl_rails (>= 1.6.0) 
    haml-rails (>= 0.3.4) 
    heroku 
    jquery-rails 
    launchy (>= 2.0.5) 
    mongoid (>= 2.4.3) 
    mongoid-rspec (>= 1.4.4) 
    quiet_assets 
    rails (= 3.2.3) 
    rspec-rails (>= 2.8.1) 
    sass-rails (~> 3.2.3) 
    simple_form 
    thin 
    uglifier (>= 1.0.3) 
+0

我假設你已將'views/sources/index.html.erb'重命名爲'views/sources/index.html.haml'? – nmott 2012-04-18 13:00:22

+0

實際上,haml-rails gem爲我生成了這些haml文件。我定製了他們,他們與webrick服務。我不認爲我有過erb文件。 – 2012-04-18 13:05:55

+0

奇怪。不應該有任何額外的配置haml工作。你重新啓動了Rails服務器嗎?您是否使用Spork與Rspec並重新啓動?或者你是否在使用Guard與Rspec並重新啓動? – nmott 2012-04-18 13:15:15

回答

2

更新:我看到了類似的問題(我現在無法找到:}),這表明添加文本

require "haml" 

到config/test.rb設置,併爲我做了訣竅。因此,我不需要在引用中指定模板處理程序,例如partials或layout,而且一切正常。

我遇到了與Rails 3.2.2,Cucumber 1.10和rspec-rails 2.8.0相同的問題。

下面的解決方法讓我解決了這個問題:我引用基於HAML的部分的任何地方,我使用該模板的全限定名稱。因此,例如要在我的網站的管理部分中引用我的管理佈局,我輸入了'layout admin.html.haml'而不是'layout admin'。同樣的偏見我用我的哈姆文件的全名,而不是沒有任何後綴的名稱,這使得RSpec和我的測試高興,

現在,我不應該必須做到這一點,我意識到在模板名稱中傳遞模板處理程序是(或將要)每here不推薦使用,但這樣可以解鎖我的測試並在生產環境中工作,直到找到正確的解決方案。

我從來沒有必要在引用中指定模板處理程序之前,我猜測它與創建後向我的網站添加HAML支持的事實有關,但是我沒有找到配置設置,我猜我錯過了。

祝你好運! Michael