有没有办法(可能是一些关键)告诉rspec跳过挂起的测试并且不打印有关它们的信息?
我有一些自动生成的测试
pending "add some examples to (or delete) #{__FILE__}"
Run Code Online (Sandbox Code Playgroud)
我运行"bundle exec rspec spec/models --format documentation"并得到这样的东西:
Rating
allows to rate first time
disallow to rate book twice
Customer
add some examples to (or delete) /home/richelieu/Code/first_model/spec/models/customer_spec.rb (PENDING: No reason given)
Category
add some examples to (or delete) /home/richelieu/Code/first_model/spec/models/category_spec.rb (PENDING: No reason given)
......
Run Code Online (Sandbox Code Playgroud)
我想保留这些文件,因为我稍后会更改它们,但是现在我想输出如下:
Rating
allows to rate first time
disallow to rate book twice
Finished in 0.14011 seconds
10 examples, 0 failures, 8 pending
Run Code Online (Sandbox Code Playgroud) class Temp1
def add(s)
match = 'test'
self.class.class_eval do
define_method(s) do
puts match
end
end
#match ='haha'
end
end
Run Code Online (Sandbox Code Playgroud)
就我而言,'match'是一个局部变量,所以我不明白它如何从另一个方法中看到它,另外如果取消注释#match ='haha',该方法将以某种方式打印'haha'。有人可以解释吗?
另外,我在这里看不到使用class_eval或instance_eval之间的区别,似乎它做同样的事情。
最后但并非最不重要的一点是,我可以在这里使用define_method创建类方法吗?所以我可以称其为Temp1.something而不是Temp1.new.something?