[英]Error during testing in rails
I am trying to run a unit test. 我正在尝试运行单元测试。
The test needs to have require_relative 'francis'
测试需要有require_relative 'francis'
require 'minitest/autorun'
require_relative 'francis'
class FrancisTest < MiniTest::Test
When I try running rake test TEST=test/francis_test.rb
I get an error of 当我尝试运行rake test TEST=test/francis_test.rb
,出现错误
(in C:/Users/chris2/Documents/RailsProjects/francis)
rake aborted!
LoadError: cannot load such file -- C:/Users/chris2/Documents/RailsProjects/francis/test/francis
C:/Users/chris2/Documents/RailsProjects/francis/test/francis_test.rb:2:in `require_relative'
C:/Users/chris2/Documents/RailsProjects/francis/test/francis_test.rb:2:in `<top (required)>'
Tasks: TOP => test:single
(See full trace by running task with --trace)
How can I run this test? 如何运行此测试?
Update 更新资料
I moved francis_test.rb to the root of the project. 我将francis_test.rb移到了项目的根目录。 I also remarked out the require_relative statement., I also had to change the setup line to @teen = ::Franci.new
instead of Francis.new 我还指出了require_relative语句。我还必须将设置行更改为@teen = ::Franci.new
而不是Francis.new
So the beginning of francis_test looks like 所以francis_test的开头看起来像
require 'minitest/autorun'
# require_relative 'franci'
require 'test_helper'
class FrancisTest < MiniTest::Test
attr_reader :teen
def setup
@teen = ::Franci.new
end
def test_stating
assert_equal 'Whatevs.', teen.yo('Oh blah di, oh blah da.')
end
def test_yelling
assert_equal 'Chill!', teen.yo('GOOOAAAALLL!')
end
I seem to need require 'test_helper'. 我似乎需要要求'test_helper'。
BTW - my ruby and rails versions are 顺便说一句-我的红宝石和Rails版本是
Rails 4.2.5.1
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
Now if I run rake test TEST=francis_test.rb -v
现在,如果我运行rake test TEST=francis_test.rb -v
I see (partial) 我看到(部分)
# Running:
FrancisTest#test_stating_with_acronyms = 0.01 s = E
FrancisTest#test_inquiring = 0.00 s = E
FrancisTest#test_question_with_just_numbers = 0.00 s = E
. . .
Finished in 0.013518s, 1257.5400 runs/s, 0.0000 assertions/s.
1) Error:
FrancisTest#test_stating_with_acronyms:
ArgumentError: wrong number of arguments (1 for 0)
2) Error:
FrancisTest#test_inquiring:
ArgumentError: wrong number of arguments (1 for 0)
A couple of questions 几个问题
BTW - the francis table only has one column - 'yo'. 顺便说一句-弗朗西斯表只有一列-'yo'。
require_relative
complements the builtin method require by allowing you to load a file that is relative to the file containing the require_relative
statement. require_relative
通过允许您加载相对于包含require_relative
语句的文件的文件来补充内置方法require。
For example, if you have unit test classes in the "test" directory, and data for them under the test "test/data" directory, then you might use a line like this in a test case: 例如,如果您在“ test”目录中有单元测试类,而在“ test / data”目录中有它们的数据,那么在测试用例中可以使用如下代码:
require_relative "data/customer_data_1"
is attr_reader valid in Ruby 2.2.4? Ruby 2.2.4中的attr_reader有效吗? I looked at the API but couldn't quite make sense of it. 我看了看API,但不太明白。
Yes, it is . 是的,是 。 However you don't need it because columns are automatically made available as attributes by ActiveRecord. 但是,您不需要它,因为ActiveRecord会自动将列用作属性。
Why am I getting 'wrong number of arguments'? 为什么会出现“参数数量错误”的情况? I haven't used the attr_reader but it seems that when calling it the way I am, it should be passing the argument to teen.yo. 我没有使用过attr_reader,但似乎以我的方式调用它时,应该将参数传递给teen.yo。
To answer this question, I need the content of your francis.rb
file. 要回答这个问题,我需要您的francis.rb
文件的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.