不知道如何构建任务'recipe_test.rb'

时间:2015-10-21 19:43:43

标签: ruby-on-rails rake-task rakefile rake-test

我知道之前会问过同样的问题,但这些问题与我的完全不同。我的.rb中有rails_app/test/integration个文件

recipe_test.rb

require "test_helper"

class RecipeFlowsTest < ActionDispatch::IntegrationTest
  fixtures :recipes
  test 'create recipes' do
    https! # sign in emulation
    curry = recipes(:curry)
    get '/recipes/new'
    assert_response :success

    post_via_redirect '/recipes/new', title: recipes(:curry).title
    assert_equal '/recipes', path
    assert_equal 'Create Recipe', flash[:notice]

    https!(false) # sign out emulation
    get '/recipes'
    assert_response :success
    assert assigns(:recipes) # fetch out inst var :recipes (in controller)
  end
end

test/fixture/recipe_test.yml

curry:
  title: Curry
  food_preference_id: 1
  food_type: 1
  cuisine_id: 1
  servings: 1
  cooking_time: 1
  level_of_difficulty: Easy
  ingredients: Onions Tomatoes Salt Oil
  procedure: Heat Oil Chop Onions,
             tomatoes and Salt to it.

这是我的test/helper_test.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
integration tests
  fixtures :all
end

现在我做rake test recipe_test.rb --trace

它给我以下错误

** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Execute test:run
rake aborted!
Don't know how to build task 'recipe_test.rb'

1 个答案:

答案 0 :(得分:4)

您的rake任务无效。 Here's a list of proper rake test tasks

你只需要

rake test

对于recipe_test,您还可以执行rake test:integration