通常,当测试失败时,我花了很长时间试图找出导致测试失败的原因.如果RSpec在测试失败时启动Ruby调试器会很有用,这样我就可以立即检查局部变量以深入了解原因.
我正在使用的解决方案现在看起来像这样:
# withing some test
debugger unless some_variable.nil?
expect(some_variable).to be_nil
Run Code Online (Sandbox Code Playgroud)
但是,这种方法很麻烦,因为我首先等待测试失败,然后添加调试器行,修复问题然后必须删除调试器行,而我希望它的工作更像是gdb哪个有能力启动时如果遇到异常,则无需使用debugger语句来编写代码库.
编辑:我试过普利茅斯.它对我来说还不够可靠.此外,开发历史似乎表明它不是一个非常受支持的宝石,所以我宁愿不依赖它.
更新:我试过去pry-rescue发现它很整洁.但是,我经常使用宙斯,并且想知道是否有办法让它适用pry-rescue.
这就是我在做的事情:
csv = CSV.open(file_name, "r")
Run Code Online (Sandbox Code Playgroud)
我用这个来测试:
line = csv.shift
while not line.nil?
puts line
line = csv.shift
end
Run Code Online (Sandbox Code Playgroud)
我碰到了这个:
ArgumentError: invalid byte sequence in UTF-8
Run Code Online (Sandbox Code Playgroud)
csv = CSV.open(file_name, "r", encoding: "windows-1251:utf-8")
Run Code Online (Sandbox Code Playgroud)
我遇到了以下错误:
Encoding::UndefinedConversionError: "\x98" to UTF-8 in conversion from Windows-1251 to UTF-8
Run Code Online (Sandbox Code Playgroud)
然后我遇到了一个Ruby gem - charlock_holmes.我想我会尝试使用它来查找源编码.
CharlockHolmes::EncodingDetector.detect(File.read(file_name))
=> {:type=>:text, :encoding=>"windows-1252", :confidence=>37, :language=>"fr"}
Run Code Online (Sandbox Code Playgroud)
所以我这样做了:
csv = CSV.open(file_name, "r", encoding: "windows-1252:utf-8")
Run Code Online (Sandbox Code Playgroud)
仍然有这个:
Encoding::UndefinedConversionError: "\x8F" to UTF-8 in conversion from Windows-1252 to UTF-8
Run Code Online (Sandbox Code Playgroud) 如果我进行翻页和向下翻页,它们就会消失.为什么会发生这种情况,我该如何纠正呢?
http://i.stack.imgur.com/DnMYl.png
我最近摆弄了我的vimrc.这可能是原因吗?
更新:我找出了原因.我添加了自动更新cwd名称和我的vim状态行中当前git分支的函数.这导致vim变得迟钝,并且每次它在上/下/左/右键击中时都会滞后,它会打印出鬼字符^ [OA等等.因为我在tmux中使用了vim,所以有可能因为我在vm中使用了vim,但是我看到tmux外面的鬼字也.所以,可能不是.我已经关闭了.vimrc中的这两个函数,我的vim状态行目前比以前更糟糕了:(希望有一条出路.
A test user on Facebook has a default @tfbnw.net email address as the primary email address, in addition to a @facebook.com address which routes to their Facebook Messages inbox.
I've tried to set the @facebook.com address as primary, since I wish to quickly check sent sample emails in their Facebook Messages inbox. However, I'm not allowed to do so [which makes sense, I guess, because the primary email id is supposed to be a non-FB one].
It's tiring to create …