小编jak*_*ake的帖子

45
推荐指数
4
解决办法
2万
查看次数

我如何使用RSpec测试Rails中的包含验证

我的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匹配器.

编辑

经过一些环顾四周我才发现,这可能是一种'好'的测试方式,如果没有为此提供任何东西,任何需要它的人都可以为它编写自己的自定义匹配器.(并可能将其贡献给项目) .可能有趣的讨论的一些链接:

  • 链接表明上述内容.链接1,链接2

  • should_ensure_value_in_range这个接近可以使用的,但只接受范围而不是值列表.自定义匹配器可以基于此.

shoulda rspec-rails ruby-on-rails-3

39
推荐指数
2
解决办法
2万
查看次数

运行osascript -e'告诉应用程序"TextMate"重新加载捆绑包时出错

我正在尝试为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)

任何帮助将不胜感激.

bash textmate cucumber textmatebundles textmate2

29
推荐指数
1
解决办法
9380
查看次数

更改在Textmate中拼写检查的语言

在OS X应用程序(如Mail和Firefox)中,您可以右键单击文本字段并更改要进行拼写检查的语言.我无法弄清楚如何在Textmate中做同样的事情.可以轻松完成,如果,如何?

macos textmate textmate2

16
推荐指数
3
解决办法
3372
查看次数

有没有人设法使用Textmate2使用较旧的Textmate捆绑包?

我特别希望能够使用Ackmate软件包,peepcode(新的'Go to file'似乎已经足够好了)以及其他一些与TM2相关的自定义软件包.

我尝试将现有的捆绑包移动到一个
~/Library/Application Support/TextMate/Managed/Bundles/Managed 似乎包含所有新安装捆绑包的位置,以及其他一些黑客攻击.但还没有运气.

我确实设法让较旧的主题与TM2一起使用,其方法类似于上面的方法.

编辑:

我在这个主题上发现了这篇文章.但仍然无法让一些旧的捆绑包工作. http://blog.macromates.com/2011/locating-bundles/

migration textmate textmate2

9
推荐指数
1
解决办法
3056
查看次数

在TextMate中我无法使用Rails tmbundle创建局部视图

/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.

textmate ruby-on-rails textmatebundles textmate2

5
推荐指数
1
解决办法
906
查看次数

使用Array的多个变量的Ruby case语句

我想比较一个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)

ruby arrays equals case

3
推荐指数
1
解决办法
3049
查看次数

TextMate真的值得作为代码编辑器的价格标签吗?

我一直在阅读很多人的帖子,对作为代码编辑器的TextMate赞不绝口,并且想知道它是否真的值得特别高价格,因为有很多免费替代品.

它真的比DashCode,TextWrangler甚至Vim/Emacs更好吗?

哪些功能设置为appart?

ide textmate text-editor editor textmate2

3
推荐指数
1
解决办法
1867
查看次数

是否有可能干扰此迁移?

我有一个表,文件夹,我想要一些其他表引用,到目前为止,我的迁移脚本如下所示:

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)

由于我对每个表基本上做同样的事情,是否有更简洁和可维护的方式来编写它?

谢谢

ruby migration activerecord ruby-on-rails dry

3
推荐指数
1
解决办法
165
查看次数

找出Hash和Array之间的变量类和差异

是否有可能清楚地识别出一类变量?

就像是:

@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等之间的区别?

ruby

0
推荐指数
1
解决办法
243
查看次数