运行以下两个命令有什么区别?
rails test test/controllers/api/<filename>
rails test
我如何知道是否存在差异?前者有效,而后者则无效。似乎并非所有装置都已加载。
更新
$ rails test:all
rails aborted!
Don't know how to build task 'test:all' (see --tasks)
$ rails --tasks
rails about # List versions of all Rails frame...
rails active_storage:install # Copy over the migration needed t...
rails active_storage:install:migrations # Copy migrations from active_stor...
rails app:template # Applies the template supplied by...
rails app:update # Update configs and some other in...
rails assets:clean[keep] # Remove old compiled assets
rails assets:clobber # Remove compiled assets
rails assets:environment # Load asset compile environment
rails assets:precompile # Compile all the assets named in ...
rails cache_digests:dependencies # Lookup first-level dependencies ...
rails cache_digests:nested_dependencies # Lookup nested dependencies for T...
rails clean # Remove any temporary products
rails clobber # Remove any generated files
rails db:create # Creates the database from DATABA...
rails db:drop # Drops the database from DATABASE...
rails db:environment:set # Set the environment value for th...
rails db:fixtures:load # Loads fixtures into the current ...
rails db:migrate # Migrate the database (options: V...
rails db:migrate:status # Display status of migrations
rails db:rollback # Rolls the schema back to the pre...
rails db:schema:cache:clear # Clears a db/schema_cache.yml file
rails db:schema:cache:dump # Creates a db/schema_cache.yml file
rails db:schema:dump # Creates a db/schema.rb file that...
rails db:schema:load # Loads a schema.rb file into the ...
rails db:seed # Loads the seed data from db/seed...
rails db:setup # Creates the database, loads the ...
rails db:structure:dump # Dumps the database structure to ...
rails db:structure:load # Recreates the databases from the...
rails db:version # Retrieves the current schema ver...
rails dev:cache # Toggle development mode caching ...
rails initializers # Print out all defined initialize...
rails log:clear # Truncates all/specified *.log fi...
rails middleware # Prints out your Rack middleware ...
rails notes # Enumerate all annotations (use n...
rails notes:custom # Enumerate a custom annotation, s...
rails restart # Restart app by touching tmp/rest...
rails routes # Print out all defined routes in ...
rails secret # Generate a cryptographically sec...
rails simplecov # Run tests
rails stats # Report code statistics (KLOCs, e...
rails test # Runs all tests in test folder ex...
rails test:db # Run tests quickly, but also rese...
rails test:system # Run system tests only
rails time:zones[country_or_offset] # List all time zones, list by two...
rails tmp:clear # Clear cache, socket and screensh...
rails tmp:create # Creates tmp directories for cach...
rails yarn:install # Install all JavaScript dependenc...
这是针对Rails 5的。为了澄清测试,请参见tests/controllers/
和tests/controllers/api
。指定时运行但未通过rails test
的测试位于api子目录中,我认为该子目录已正常加载。我可以看到正在运行测试,但是未正确加载夹具。但是,我已将文件移至tests/
进行故障排除,但问题仍未解决,因此我认为这不是问题。
答案 0 :(得分:1)
rails test
用于测试test/
文件夹中的所有测试。
rails test <file_path>
用于在不同位置而不是test/*.*
文件中进行测试。因此,当您的测试文件不在test/
中时,尤其适用。
您可以使用rails test:all
测试test/
文件夹的所有子目录文件。
答案 1 :(得分:1)
首先,我看到您的项目中没有这样的rake任务rails test:all
,这就是为什么它无法构建任务的原因。
rails test
是一次运行所有测试的命令,而rails test filepath
仅用于测试指定的文件。类似于运行系统测试,请使用rails test:system