我试图让这个工作:
link_to("#", class: "add_fields btn btn-success") do
name
content_tag(:i, "", :class => "icon-plus icon-white")
end
Run Code Online (Sandbox Code Playgroud)
但它只显示i(twitter-bootstrap css)指定的图标而不是文本name,我做错了什么?
我已经在我的Rails 3.1应用程序上成功配置了https://github.com/galetahub/ckeditor的ckeditor gem .我现在的问题是我无法弄清楚如何配置CKEditor.在启用了资产管道的Rails 3.1应用程序中,根据自述文件使用的文件根本不存在.
我已经创建了一个Rails可安装应用程序并添加了'mongoid'和'rspec'gem.如果我现在尝试运行我的规格,我会收到以下错误:
Mongoid::Errors::NoSessionConfig:
Problem:
No configuration could be found for a session named 'default'.
Summary:
When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash. …Run Code Online (Sandbox Code Playgroud) 我有一个RSpec测试/lib/classes,需要访问一个zip文件(没有上传).该文件存储在/spec/fixtures/files/test.zip.如何输入正确的路径以使其与环境无关,即没有绝对路径?
我有一个使用rails 3.2和Devise的应用程序.我有一个使用rspec和Capybara的请求测试套件.
我试图在我的登录帮助中转而使用Warden测试助手,而不是让Capybara填写登录表单并提交.由于我的测试套件的大小和复杂性,这导致我的测试运行时节省超过一分半.
在我的配置是:
RSpec.configure do |config|
config.include Warden::Test::Helpers, :type => :request
config.after :each do
Warden.test_reset!
end
end
Run Code Online (Sandbox Code Playgroud)
并在上下文中:
let!(:current_user) { FactoryGirl.create(:user) }
background do
login_as(current_user, :scope => :user)
end
Run Code Online (Sandbox Code Playgroud)
但是,当使用这些配置运行测试套件时,几乎每个测试运行都会有一个不同的随机失败的请求规范,因为页面呈现就好像用户没有登录一样.(具体来说,由user_signed_in?条件控制的链接)
我的问题:是否有其他人遇到过这种不可靠性以及如何减轻这种不可靠性?
我想在我的工厂中干掉后创建/构建钩子:
FactoryGirl.define do
factory :poll do
sequence :title do |n|
"MyPollTitle#{n}"
end
sequence :description do |n|
"MyPollDescription#{n}"
end
user
factory :poll_with_answers do
ignore do
answers_count 2
end
after(:build) do |poll, evaluator|
evaluator.answers_count.times do
poll.answers << build(:answer, poll: poll)
end
end
after(:create) do |poll, evaluator|
evaluator.answers_count.times do
poll.answers << create(:answer, poll: poll)
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,我似乎无法在FG中定义方法?想法如何干这个?
对于rails模板,我想在新的rails应用程序中添加特定标签的子模块.为了保持这个简单,我想避免进入子目录并在那里运行git命令.
git submodule add --branch v1.3.37 git@example.com:foo.git vendor/foo
是我想要使用的,但它不接受--branch参数的标签:
fatal: 'origin/v1.3.37' is not a commit and a branch 'v1.3.37 cannot be created from it Unable to checkout submodule 'vendor/foo'
有没有一种简单的方法在特定标签上添加git子模块?
我已经为我的rails 3.2应用程序编写了一些RSpec测试,因为我被浏览器弹出了ich试图从firefox改为capybara-webkit.在此之后,所有测试仍在运行,除了一个.失败的线是:
expect { click_button "Create" }.to change(Answer, :count).by(count)
Run Code Online (Sandbox Code Playgroud)
如果我删除了expect并添加了一个方法来截取前后的截图,我可以看到测试运行正常.但是,如果我通过调试器进入低谷,日志会显示在第二个屏幕截图行之后创建记录.我可以永远等待click_button,并在执行第一行后运行相应的Controller操作.
"创建"按钮是标准的html按钮,创建操作中不涉及JS.某人对这种奇怪的行为有解释吗?
我有以下初始化程序:
应用程序/配置/初始化/ store_location.rb
module StoreLocation
def self.skip_store_location
[
Devise::SessionsController,
Devise::RegistrationsController,
Devise::PasswordsController
].each do |controller|
controller.skip_before_filter :store_location
end
end
self.skip_store_location
end
Run Code Online (Sandbox Code Playgroud)
我的ApplicationController的相关部分:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :convert_legacy_cookies
before_filter :store_location
alias_method :devise_current_user, :current_user
def current_user
# do something
end
private
def store_location
# store location
end
Run Code Online (Sandbox Code Playgroud)
另外在 config/environments/development.rb中
Foo::Application.configure do
# normal rails stuff
config.to_prepare do
StoreLocation.skip_store_location
end
end
Run Code Online (Sandbox Code Playgroud)
如果我让RSpec/Rails运行self.skip_store_location,我收到以下错误:
/foo/app/controllers/application_controller.rb:7:in `alias_method': undefined method `current_user' for class `ApplicationController' (NameError)
Run Code Online (Sandbox Code Playgroud)
如果我删除了呼叫,一切都恢复正常(除了按预期运行过滤器).我猜我以某种方式搞乱了依赖加载?
我的模板之一中有以下 haml 代码:
%b= t ('activerecord.attributes.exercise.title') + ':'
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方法来实现这一目标?最好是oneliner,没有括号。
rspec希望您的控制器规格在/ spec/controllers中.我有一些模块包含在我的控制器中.正如我所知,测试它们的唯一方法是创建一个虚拟控制器,在其中包含模块,然后从那里进行测试.问题是模块规格在/ spec/lib/module中,因此不包含ControllerExampleGroup,这意味着我无法调用辅助方法得到"动作"等.
我可以手动导入这些,这让我大部分都在那里,但我得到这个错误:
Failure/Error: Unable to find matching
line from backtrace undefined method
`path_set' for nil:NilClass
activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in
`method_missing'
rspec-rails-2.2.1/lib/rspec/rails/view_rendering.rb:68
rspec-core-2.2.1/lib/rspec/core/example_group.rb:291:in
`instance_eval'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:291:in
`instance_eval_with_rescue'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:39:in
`run_in'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:70:in
`run_all'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:70:in
`each'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:70:in
`run_all'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:106:in
`run_hook'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:194:in
`eval_after_eachs'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:194:in
`each'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:194:in
`eval_after_eachs'
rspec-core-2.2.1/lib/rspec/core/example.rb:130:in `run_after_each'
rspec-core-2.2.1/lib/rspec/core/example.rb:44:in `run'
rspec-core-2.2.1/lib/rspec/core/example.rb:88:in `with_around_hooks'
rspec-core-2.2.1/lib/rspec/core/example.rb:37:in `run'
rspec-core-2.2.1/lib/rspec/core/example.rb:81:in `with_pending_capture'
rspec-core-2.2.1/lib/rspec/core/example.rb:80:in `catch'
rspec-core-2.2.1/lib/rspec/core/example.rb:80:in `with_pending_capture'
rspec-core-2.2.1/lib/rspec/core/example.rb:36:in `run'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:261:in
`run_examples'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:257:in
`map'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:257:in
`run_examples'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:231:in
`run'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:232:in
`run'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:232:in
`map'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:232:in
`run'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:27:in
`run'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:27:in
`map'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:27:in
`run'
rspec-core-2.2.1/lib/rspec/core/reporter.rb:12:in `report'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:24:in
`run' …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试我的标题标签application/layout.html.erb:
<title><%= content_for?(:title) ? yield(:title) : "Foo Bar" %></title>
Run Code Online (Sandbox Code Playgroud)
但我发现无法设置title变量:
it "should show a title" do
# NameError: `title' is not allowed as an instance variable name
#view.instance_variable_set(:title, 'Test Title')
# Deprecation error
# view.stub(:title) { 'Test Title' }
# Fail:
# allow(view).to receive(:title) { 'Test Title' }
# view.content_for(:title) { 'Test Title' }
# assign(:title, 'Test Title')
# helper.stub(:content_for).with(:title).and_return('Test Title')
render
expect(rendered).to have_title('Test Title')
end
Run Code Online (Sandbox Code Playgroud)
我正在使用Rails 4.1.4,rspec-rails 3.0.2,Capybara 2.4.1.有什么建议?
我有:
val = [{uid: '1', ignore: 'i1'}, {:uid: '2', ignore: 'i2'}]
Run Code Online (Sandbox Code Playgroud)
现在我想将部件提取:uid到一个数组中:
arr = []
val.each { |u| u.map { |k,v| arr << v if :uid == k } }
Run Code Online (Sandbox Code Playgroud)
是否有更优雅/更短的方式来写最后两行?