我正在使用"带有Rails 4"的书"敏捷Web开发",并且正在通过第7章,这与测试有关。该教程包括一个产品模型,并让读取器修改测试文件product_test.rb
,显然应该在test/models.
中的测试指南中也具有此结构。但是由于某种原因,我的测试目录中没有模型子目录。我的测试目录看起来像这样:
[~/code/depot]: ls test
fixtures functional integration performance test_helper.rb unit
我的product_test.rb
文件在"单元"文件夹中。
当我尝试运行书中所示的测试时,这会导致问题。rake test
和ruby -Itest test/unit/product_test.rb
一样工作正常,但是rake test:models
产生以下错误:
[~/code/depot]: rake test:models
rake aborted!
Don't know how to build task 'test:models'
(See full trace by running task with --trace)
我不太了解耙子命令,但是我假设当我运行rake test:models
时它正在寻找test/models
吗?无论如何,它不起作用,我不知道为什么我的测试目录结构缺少模型文件夹以及为什么我的product_test.rb
代替test/unit
。测试导轨指南还表明脚手架生成的模型应在test/models
中进行测试。谁能解释可能发生的事情或我应该如何解决此问题?
编辑
rake -T
的输出:
[~/code/depot]: rake -T
rake about # List versions of all Rails frameworks and the environment
rake assets:clean # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:crea...
rake db:drop # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load # Load fixtures into the current environment's database
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false)
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop ...
rake db:structure:dump # Dump the database structure to db/structure.sql
rake db:version # Retrieves the current schema version number
rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/...
rake log:clear # Truncates all *.log files in log/ to zero bytes
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update # Update configs and some other initially generated files (or use just update:configs, update:scripts...
rake routes # Print out all defined routes in match order, with names
rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for coo...
rake stats # Report code statistics (KLOCs, etc) from the application
rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:...
rake test:recent # Run tests for {:recent=>"test:prepare"} / Test recent changes
rake test:single # Run tests for {:single=>"test:prepare"}
rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Test changes since last checkin (only Subversion and...
rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET para...
rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tm...
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
您的应用程序中有类似以下内容。
config.generators do |g|
g.fixture_replacement :factory_girl # if your using factory_girl
g.test_framework :test_unit, :spec => true, :fixture => false
end