我在lib/tasks中有以下任务:
task :cuke_test_db_constraints do
puts 'cuke_test_db_constraints'
ENV['TEST_DB_CONSTRAINTS'] = '1'
Rake::Task['cucumber'].reenable
Rake::Task['cucumber'].invoke
end
task :default => :cuke_test_db_constraints
如你所见,我想在设置一个env变量后再次运行黄瓜.但是,当cuke_test_db_constraints任务运行时,黄瓜不会运行场景.黄瓜任务本身运行,我检查它添加调试输出下:lib/tasks/cucumber.rake中的黄瓜任务.
有任何想法吗?谢谢.
快速的问题.
我在linux下运行pygame只是为了播放一些音频文件.我有一些.wav文件,我在以正确的速度回放它时遇到问题.
import pygame.mixer, sys, time
#plays too fast
pygame.mixer.init(44100)
pygame.mixer.music.load(sys.argv[1])
pygame.mixer.music.play()
time.sleep(5)
pygame.mixer.quit()
#plays too slow
pygame.mixer.init(22100)
pygame.mixer.music.load(sys.argv[1])
pygame.mixer.music.play()
time.sleep(5)
pygame.mixer.quit()
Run Code Online (Sandbox Code Playgroud)
我有ggogle代码搜索了一些东西但是每个人似乎都很好用默认参数调用init函数.其他人可以尝试运行此脚本并查看它们是否获得相同的行为?有人知道如何加快速度吗?或者调整每个文件的速度?
谢谢.
我正在运行Resque后台任务,并在调用使用Rjb的gem时不断出现分段错误.但是,当不在后台运行时,一切正常.这是gem中的一行,导致错误:
def self.rjb_initialize
return if ::Rjb::loaded?
::Rjb::load(nil, self.jvm_args) #THIS IS WHERE THE ERROR TRACES TO
set_java_logging if self.log_file
end
Run Code Online (Sandbox Code Playgroud)
宝石加载.jar文件,你可以看到,但同样,一切都很完美,当不在后台时.什么可能导致问题,是否可以修复它?
ruby-on-rails background-process segmentation-fault ruby-on-rails-3 rjb
我有两个型号Content和ContentType.在内容模型中,我可以这样做:
def get_all_content_except_poking_message
Content.all.where(:name.ne => "no forking, just poking")
end
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试在ContentType上应用范围.在内容模型中再次:
# Associations
belongs_to :content_type
def get_all_content_except_certain_content_type(content_type)
Content.all.where(:content_type.name.ne => content_type)
end
Run Code Online (Sandbox Code Playgroud)
但错误表明它在关联字段上应用范围的语法错误.
在模型中的关联字段上应用范围的正确方法是什么?
我也在使用has_scope gem.我也可以在控制器中应用相同的过滤器吗?就像是:
@contents = apply_scopes(
if params[:type]
@content_type = ContentType.find_by_slug(params[:type])
@content_type.contents.all
else
Content.all.where (:content_type.name.ne => "blogs")
end
)
Run Code Online (Sandbox Code Playgroud)
为了澄清,这里是irb输出:
irb(main):020:0> ContentType.all(:name=>"blogs").count
=> 1
irb(main):023:0> Content.last.content_type.name
=> "blogs"
irb(main):024:0> Content.all.where(:content_type => {:name => {'$ne' => "blogs"}}).count
=> 0
irb(main):026:0> Content.all.count
=> 4
Run Code Online (Sandbox Code Playgroud) model-view-controller ruby-on-rails mongodb mongoid has-scope
我不确定将几个模块包含在RSpec中的方法,所以让我来描述一下我的情况.
在app/helpers我有两个文件与助手,包含模块ApplicationHelper和MailersHelper.虽然这些是我在视图和邮件中使用的视图助手,但我也在我的测试中使用了一些方法,所以它们必须在describe子句中可访问.
在app/spec/mailers我下面还有一个包含模块的文件Helpers.该模块包含仅在测试中使用的方法(主要是长期望的包装方法).
另外,我有以下代码:
class Helpers
include Singleton
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::NumberHelper
end
def helper
Helper.instance
end
Run Code Online (Sandbox Code Playgroud)
它的目的是使测试中的视图助手可用.目前,此代码位于Helper包装器方法之前的模块中,因为它们使用该Helper.instance方法.
我有三个邮件,我想测试.那么如何在测试中使所有这些东西都可以访问?
在每个邮件程序规范中直接使用include,如下所示:
require 'spec_helper'
describe MyMailer do
include ApplicationHelper
include MailersHelper
include Helpers
...
end
Run Code Online (Sandbox Code Playgroud)
在文件中helpers.rb我这样做:
require 'spec_helper'
module Helpers
include MailersHelper
include ApplicationHelper
...
end
RSpec.configure { |c| c.include Helpers }
Run Code Online (Sandbox Code Playgroud)
并在我使用的每个邮件规范中 require_relative './helpers'
和上面一样但不是包括ApplicationHelper与MailersHelper中Helpers …
我想在Rails中将ERB模板呈现为纯文本.理想情况下,我可以做这样的事情:
应用程序/视图/测试/ test.txt.erb
Test
<%= @test %>
Run Code Online (Sandbox Code Playgroud)
当我尝试时,Rails抱怨以下错误:
ActionView::MissingTemplate (Missing template test/test, application/test with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}. Searched in:
* "/Users/landonschropp/Development/test/app/views"
):
Run Code Online (Sandbox Code Playgroud) 我在服务器端javascript(SSJS)按钮中设置了一个viewScope变量.
viewScope.put( "分支名称",doc.getItemValueString( "分支名称"))
如何在客户端访问该变量?
我是Android新手.我刚刚安装了Android Studio并创建了一个默认项目.现在我正在尝试创建AVD但我无法创建.确定按钮未启用.请帮忙.
我需要从Bitbucket克隆一个存储库,我被另一个用户访问了.
我试过这个:
git clone myusername@bitbucket.org:repositoryOwnerUserName/repo.git
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误信息:Permission denied(publickey).
我如何克隆这个存储库?
我已经将rails应用程序配置为使用Active资源来使用Redmine api.在我的模型redmine.rb中,我输入以下代码
require 'active_resource'
class Redmine < ActiveResource::Base
self.site = "http://localhost:9000/"
self.format = :json
self.element_name = "issues"
self.user = "admin"
self.password = "admin"
end
Run Code Online (Sandbox Code Playgroud)
在我的控制器
def index
@data = Redmine.find(:all)
end
Run Code Online (Sandbox Code Playgroud)
但它显示参数错误ArgumentError在预期的属性Hash,得到并显示带有此错误的json数据.
如何摆脱这个错误,我正在使用
gem 'activeresource', :require => 'active_resource'
Run Code Online (Sandbox Code Playgroud)
但是当我使用XML解析时它没有显示任何错误,那么我认为问题在于json解析.请帮我搞清楚.