1

私はRailsは初めてですが、ソフトウェア開発は初めてではないので、これらのいくつかは初歩的な質問と頭を悩ませる質問が混在している可能性があります.

私たちはアプリでベンチマークを取得しようとしていますが、Rails、Capybara、およびデータベースをうまく連携させるのにイライラする瞬間があります。

すでにデータで満たされたデータベースがあるので、そこから始めることにしました。これは、テストを作成して db し、実行するために私が書いたスクリプトです。

 #!/bin/bash

 RAILS_ENV=test

 RAILS_ENV=$RAILS_ENV rake db:drop

 RAILS_ENV=$RAILS_ENV rake db:create

 RAILS_ENV=$RAILS_ENV rake db:migrate

 RAILS_ENV=$RAILS_ENV rake demo:data:load

 RAILS_ENV=$RAILS_ENV  rake test:benchmark

これは私が書いた簡単なテストです:

require 'test_helper'
require 'rails/performance_test_help'

require 'capybara/rails'

# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionDispatch::PerformanceTest
  def setup
     sign_in "fred"
  end
  def test_dashboard
     get '/dashboard'
     get '/question_collections'
     get '/question_collections/5'
     get '/question_collections/5/questions/60'

     get '/message_collections'

   end

end

そして、次のエラーが表示されます。

  NoMethodError: undefined method `sign_in' for 
     test_dashboard(BrowsingTest):BrowsingTest.test/performance/browsing_test.rb:7:in `setup'

したがって、Capybara が見つからないように見えますが、機能テストでかなり使用しているため、これは奇妙です。次に、独自のバージョンのログインを展開して、次のように思いつきました。

require 'test_helper'
require 'rails/performance_test_help'

# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionDispatch::PerformanceTest
   def setup
     login_as
   end
  def test_dashboard
   .....
  end

def login_as
  open_session do |sess|

    user = {}
    user["username"]='fred'
    user["password"]='*****'
    sess.post "/users/sign_in", :user=>user

  end
  end

end

そして、少なくとも、それが実行され、メトリクスが得られました。しかし、ログに次のように表示されます。

 Started POST "/users/sign_in" for 127.0.0.1 at 2013-04-23 10:09:54 -0500
 Processing by DualLoginController#create as HTML
   Parameters: {"user"=>{"username"=>"fred", "password"=>"[FILTERED]"}}
  Completed 401 Unauthorized in 24ms
  Processing by DualLoginController#new as HTML
 Parameters: {"user"=>{"username"=>"fred", "password"=>"[FILTERED]"}}
  Rendered devise/shared/_links.erb (1.5ms)
  Rendered devise/sessions/new.html.erb within layouts/application (79.6ms)
 Completed 200 OK in 277ms (Views: 189.2ms | ActiveRecord: 0.0ms)

 Started GET "/dashboard" for 127.0.0.1 at 2013-04-23 10:09:55 -0500
   Processing by DashboardController#index as HTML
 Completed 401 Unauthorized in 1ms

ユーザーがログインした (おそらく) ようですが、「/dashboard」にアクセスできませんでした。他のコントローラーは同じです。単純に実行すると、rake demo:data:load && rails sログインでき、正常にfred動作します。

私は、カピバラの問題とデータベースの問題が関連していると考えています-何らかの理由rake test:benchmarkで、テスト環境で実行されていないため、データが見つからず、カピバラがロードされていません。

誰にも考えはありますか?

4

0 に答える 0