[英]Testing a method with RSpec? (Rails)
My question is I have a module which is going back to a controller and I want to test it with RSpec but its not a class / there is no class inside the module its just a method so how would I test for example the methods return values , here is what I currently have in my module, 我的问题是我有一个要回到控制器的模块,我想用RSpec对其进行测试,但它不是一个类/模块内没有类,它只是一个方法,所以我将如何测试例如方法的返回值,这是我当前在模块中所拥有的,
require 'rspec'
module LeagueModule
module ScrapeProPlayers
def scrape
players = []
return players
end
end
end
describe LeagueModule::ScrapeProPlayers do
it "Check for any pro players" do
host = Object.new.extend(LeagueModule::ScrapeProPlayers)
host.scrape.should == 0
end
end
Ok I figured it out this firstly I shouldn't of been using 'should' its better to use 'expect' and that was the wrong way of writing it : 好的,我首先弄清楚了这一点,我不应该一直在使用“应该”更好地使用“期望”,这是错误的编写方式:
describe LeagueModule::ScrapeProPlayers do
it "Check for any pro players" do
host = Object.new.extend(LeagueModule::ScrapeProPlayers)
result = host.scrape
expect(result.length).to eq(0)
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.