我的ActiveRecord中有以下验证.
validates :active, :inclusion => {:in => ['Y', 'N']}
Run Code Online (Sandbox Code Playgroud)
我使用以下来测试我的模型验证.
should_not allow_value('A').for(:active)
should allow_value('Y').for(:active)
should allow_value('N').for(:active)
Run Code Online (Sandbox Code Playgroud)
是否有更清洁,更通过测试方式?我目前正在使用RSpec2和shoulda匹配器.
编辑
经过一些环顾四周我才发现,这可能是一种'好'的测试方式,如果没有为此提供任何东西,任何需要它的人都可以为它编写自己的自定义匹配器.(并可能将其贡献给项目) .可能有趣的讨论的一些链接:
我正在尝试为TextMate2安装Cucumber包.我按照官方网页https://github.com/cucumber/cucumber-tmbundle的以下说明进行操作:
mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/cucumber/cucumber-tmbundle.git Cucumber.tmbundle
osascript -e 'tell app "TextMate" to reload bundles'
Run Code Online (Sandbox Code Playgroud)
运行第4行:osascript -e'告诉应用程序"TextMate"重新加载包'后,我收到以下错误:
23:37: syntax error: A identifier can’t go after this identifier. (-2740)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
在OS X应用程序(如Mail和Firefox)中,您可以右键单击文本字段并更改要进行拼写检查的语言.我无法弄清楚如何在Textmate中做同样的事情.可以轻松完成,如果,如何?
我特别希望能够使用Ackmate软件包,peepcode(新的'Go to file'似乎已经足够好了)以及其他一些与TM2相关的自定义软件包.
我尝试将现有的捆绑包移动到一个
~/Library/Application Support/TextMate/Managed/Bundles/Managed
似乎包含所有新安装捆绑包的位置,以及其他一些黑客攻击.但还没有运气.
我确实设法让较旧的主题与TM2一起使用,其方法类似于上面的方法.
编辑:
我在这个主题上发现了这篇文章.但仍然无法让一些旧的捆绑包工作. http://blog.macromates.com/2011/locating-bundles/
/Applications/TextMate.app/Contents/SharedSupport/Support/lib/ui.rb:355:in `to_plist': An object in the argument tree could not be converted (ArgumentError)
from /Applications/TextMate.app/Contents/SharedSupport/Support/lib/ui.rb:355:in `request_string_core'
from /Applications/TextMate.app/Contents/SharedSupport/Support/lib/ui.rb:193:in `request_string'
from /Users/pma/Library/Application Support/TextMate/Bundles/Ruby on Rails.tmbundle/Support/bin/create_partial_from_selection.rb:23:in `<main>'
Run Code Online (Sandbox Code Playgroud)
我安装了RoR软件包:https://github.com/drnic/ruby-on-rails-tmbundle.git
使用rvm.
我想比较一个case语句的多个变量,并且我正在考虑重写case equals operator(===)for Array是最好的方法.这是最好的方法吗?
这是一个示例用例:
def deposit_apr deposit,apr
# deposit: can be nil or 2 length Array of [nil or Float, String]
# apr: can be nil or Float
case [deposit,apr]
when [[Float,String],Float]
puts "#{deposit[0]} #{deposit[1]}, #{apr*100.0}% APR"
when [[nil,String],Float]
puts "#{apr*100.0}% APR on deposits greater than 100 #{deposit[1]}"
when [[Float,String],nil]
puts "#{deposit[0]} #{deposit[1]}"
else
puts 'N/A'
end
end
Run Code Online (Sandbox Code Playgroud)
唯一的问题是Array case equals运算符不适用大小等于Array的元素.
ruby-1.9.2-p0 > deposit_apr([656.00,'rupees'],0.065)
N/A
Run Code Online (Sandbox Code Playgroud)
如果我覆盖它,但我不确定如果我做了什么我会破坏:
class Array
def ===(other)
result = true
self.zip(other) {|bp,ap| result &&= bp === …Run Code Online (Sandbox Code Playgroud) 我一直在阅读很多人的帖子,对作为代码编辑器的TextMate赞不绝口,并且想知道它是否真的值得特别高价格,因为有很多免费替代品.
它真的比DashCode,TextWrangler甚至Vim/Emacs更好吗?
哪些功能设置为appart?
我有一个表,文件夹,我想要一些其他表引用,到目前为止,我的迁移脚本如下所示:
create_table :folders do |t|
t.timestamps
end
....
change_table table1 do |t|
t.references :folders
end
change_table table2 do |t|
t.references :folders
end
change_table table3 do |t|
t.references :folders
end
change_table table4 do |t|
t.references :folders
end
Run Code Online (Sandbox Code Playgroud)
由于我对每个表基本上做同样的事情,是否有更简洁和可维护的方式来编写它?
谢谢
是否有可能清楚地识别出一类变量?
就像是:
@users.who_r_u? #=>Class (some information)
@packs.who_r_u? #=> Array (some information)
Run Code Online (Sandbox Code Playgroud)
等等
有人能否清楚地解释Class,Hash,Array,Associated Array等之间的区别?