Я использую книгу «Гибкая веб-разработка с Rails 4» и просматриваю главу 7, посвященную тестированию. Учебное пособие включает в себя модель продукта и предлагает читателю изменить тестовый файл product_test.rb
, который, по-видимому, должен быть в test/models.
Руководстве по тестированию Railes также имеет такую структуру. Однако по какой-то причине у меня нет подкаталога моделей в моем тестовом каталоге. Мой тестовый каталог выглядит так:
[~/code/depot]: ls test
fixtures functional integration performance test_helper.rb unit
Мой файл product_test.rb
находится в папке "unit".
Это вызывает проблемы, когда я пытаюсь запустить тесты, как показано в книге. 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
, когда я запускаю rake test:models
? В любом случае, это не работает, и я понятия не имею, почему в моей тестовой структуре каталогов отсутствует папка моделей и почему мой product_test.rb
вместо этого находится в test/unit
. Руководство Rails по тестированию также указывает, что модели, сгенерированные скаффолдом, должны иметь тесты в 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