我希望能够运行单个spec文件的测试 - 例如,我正在编辑的一个文件. rake spec
执行所有规格.我的项目不是Rails项目,所以rake spec:doc
不起作用.
不知道这是否重要,但这是我的目录结构.
./Rakefile ./lib ./lib/cushion.rb ./lib/cushion ./lib/cushion/doc.rb ./lib/cushion/db.rb ./spec ./spec/spec.opts ./spec/spec_helper.rb ./spec/db_spec.rb
我希望以以下格式显示日期:短星期,短月,月中没有前导零但包括"th","st","nd"或"rd"后缀.
例如,问这个问题的那天会显示"Thu Oct 2nd".
我正在使用Ruby 1.8.7,而Time.strftime似乎并没有这样做.如果存在标准库,我更喜欢它.
据我所知,CouchDB索引在查询视图时会更新.假设有更多的读取而不是写入,这对缩放来说不是很糟糕吗?如何配置CouchDB以更新写入索引,或者更好地按时间表更新?
我希望能够在我的Ruby代码中编写lambda/Proc,将其序列化以便我可以将其写入磁盘,然后再执行lambda.有点像......
x = 40
f = lambda { |y| x + y }
save_for_later(f)
Run Code Online (Sandbox Code Playgroud)
后来,在另一个Ruby解释器的运行中,我想能够说...
f = load_from_before
z = f.call(2)
z.should == 42
Run Code Online (Sandbox Code Playgroud)
Marshal.dump不适用于Procs.我知道Perl有Data :: Dump :: Streamer,而在Lisp中这是微不足道的.但有没有办法在Ruby中做到这一点?换句话说,实施什么?save
_
for_
later
编辑:我的答案很好,但它不会关闭自由变量(如x
)并将它们与lambda序列化.所以在我的例子中......
x = 40
s = save_for_later { |y| x + y }
# => "lambda { |y|\n (x + y)\n}"
Run Code Online (Sandbox Code Playgroud)
...字符串输出不包含的定义x
.是否有一个解决方案考虑到这一点,可能是通过序列化符号表?你可以在Ruby中访问它吗?
编辑2:我更新了我的答案,以结合序列化局部变量.这似乎可以接受.
我的帮助程序代码看起来像这样(并且工作正常btw):
module ProvidersHelper
def call_to_review(provider)
if user_signed_in? && review = Review.find_by_provider_id_and_user_id(provider.id, current_user.id)
link_to "Edit Your Review", edit_provider_review_path(provider, review), :class => "call_to_review"
else
link_to "Review This Provider", new_provider_review_path(provider), :class => "call_to_review"
end
end
end
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我运行我的测试时,这会产生以下错误:
undefined method `user_signed_in?' for #<ActionView::Base:0x00000106314640>
# ./app/helpers/providers_helper.rb:3:in `call_to_review'
Run Code Online (Sandbox Code Playgroud)
很明显,Devise::Controllers::Helpers
当rspec运行测试时,我的帮助程序中没有包含这些内容.任何可能有助于此工作的建议?
编辑:为了提供更多信息,我的spec_helper确实有这个:
config.include Devise::TestHelpers, :type => :controller
config.include Devise::TestHelpers, :type => :view
config.include Devise::TestHelpers, :type => :helper
Run Code Online (Sandbox Code Playgroud)
(可悲的是,我无法使用它:type => [:controller, :view, :helper]
)
无论如何,我相信这些行将sign_in(scope, object)
(和其他)测试助手添加到您的测试中.它们不会添加您在控制器/视图代码中实际使用的帮助程序.
有没有办法在Ruby中访问符号表中的所有内容?我希望能够序列化或以其他方式保存程序运行的当前状态.为此,我似乎需要能够遍历范围内的所有变量.
让我说我有一个应用程序,我希望它是独立可执行的.我发现你可以使用https://github.com/rogerwang/node-webkit使用普通的网页,webapps来做到这一点.
但如果它的Chrome打包应用程序你怎么做.
我知道它可以在幻灯片中看到它使用webkit.
https://speakerdeck.com/u/zcbenz/p/node-webkit-app-runtime-based-on-chromium-and-node-dot-js
在Solr中,NOT和-(减号)运算符之间有区别吗?如果是这样,那是什么?
Solr文档引用了Lucene Query Parser Syntax,在此问题上含糊不清。这两个运算符的功能似乎相同,但尚不清楚。
我们正在编写一个FQL查询,该查询使用READ_STREAM查看该朋友何时更改了他们的关系状态(并将该信息公开)和/或当前城市.在这种情况下,此人的当前relationship_status设置为"单个".然后,我们运行一个查询,以查看用户何时从"处于关系中"变为"单一".
SELECT post_id, created_time, source_id, actor_id, target_id, message, description, type FROM stream WHERE source_id = 100003540518168 and (strpos(description, 'relationship') >= 0 or strpos(description, 'Relationship') >= 0 or strpos(description, 'single') >= 0 or strpos(description, 'Single') >= 0) LIMIT 500
Run Code Online (Sandbox Code Playgroud)
它返回那些朋友从关系变为单身的实例,而不返回任何显示她何时进入该关系的信息(查询只查找单词,而不查找特定顺序的单词,任何内容)用单词关系和单词应该出现,无论如何).现在,让我们将她当前的relationship_status更改为"In a Relationship"并运行完全相同的查询.
SELECT post_id, created_time, source_id, actor_id, target_id, message, description, type FROM stream WHERE source_id = 100003540518168 and (strpos(description, 'relationship') >= 0 or strpos(description, 'Relationship') >= 0 or strpos(description, 'single') >= 0 or strpos(description, 'Single') >= 0) LIMIT 500
Run Code Online (Sandbox Code Playgroud)
它只返回显示她何时进入关系的数据,而不提及她变成单身的任何内容,即使我们清楚地知道这些数据是从我们之前的查询中存在的.
我们使用"当前城市"变量复制了相同的内容.如果您已将当前城市列为加利福尼亚州洛杉矶,那么请更新您的时间线以反映移动到另一个城市(例如加利福尼亚州圣莫尼卡),您在洛杉矶居住的所有历史记录都已消失.但是,如果你将"现在的城市"改回洛杉矶,那么你在洛杉矶生活的所有时间都会回归并且现在可以使用,而没有提到圣莫尼卡.这证明它不是特定于关系状态. …
我正在关注Lynda.com的Ruby on Rail 3 Essential Training教程.我很难创建一个Active Record Entry.这是我在控制台中遇到的错误.
1.9.3p125 :007 > user = User.new(:first_name => "Mike", :last_name => "Jones")
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: first_name, last_name
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.3/lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.3/lib/active_record/base.rb:498:in `initialize'
from (irb):7:in `new'
from (irb):7
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /home/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>`
Run Code Online (Sandbox Code Playgroud)
这就是我的模型中的内容:
class User < ActiveRecord::Base
attr_accessible :first_name, :last_name
end
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么.我有轨道3.2.3
我正在使用git附带的post-receive-email脚本.(来源在这里.)它工作正常,但我希望每个电子邮件都是从提交的作者发送的.我该怎么做?
我的post-receive文件目前看起来像这样,我想自定义from-email-address.
#!/bin/sh
export USER_EMAIL=from-email-address@blah.com
$(dirname $0)/post-receive-email
Run Code Online (Sandbox Code Playgroud) ruby ×4
activerecord ×1
couchdb ×1
database ×1
date ×1
devise ×1
email ×1
facebook ×1
facebook-fql ×1
git ×1
haskell ×1
hook ×1
lambda ×1
lucene ×1
memoization ×1
monads ×1
node-webkit ×1
node.js ×1
operators ×1
post-commit ×1
proc-object ×1
rspec ×1
rspec2 ×1
scaling ×1
solr ×1
stream ×1
symbols ×1
testing ×1
webkit ×1