当我的规格出现错误时,我收到如下消息:
Vendor should reject duplicate names
Failure/Error: user_with_duplicate_email.should_not be_valid
expected valid? to return false, got true
# /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/rspec-expectations-2.3.0/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
# /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/rspec-expectations-2.3.0/lib/rspec/expectations/handler.rb:44:in `handle_matcher'
# /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/rspec-expectations-2.3.0/lib/rspec/expectations/extensions/kernel.rb:50:in `should_not'
.
.
about 15 more lines
.
.
# /home/kevin/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
# /home/kevin/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
# /home/kevin/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
Run Code Online (Sandbox Code Playgroud)
我正在运行Ruby 1.0.2,rails(3.0.3)和rspec(2.3.0).M .rspec配置文件只指定了两个选项:
--drb --colour
如何关闭扩展跟踪?
Noob可能会遗漏一些明显的东西...我正在尝试调试Rspec文件.此时Rsspec文件被删除:
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
describe "when not signed in" do
before(:each) do
get :home
end
it "should be successful" do
response.should be_success
end
it "should have a vendor section" do
response.should have_selector("h1", :content => "Vendor")
end
it "should have a hospital section" do
response.should have_selector("h1", :content => "Hospital")
end
end
end
Run Code Online (Sandbox Code Playgroud)
我从命令行进行以下调用:
rdebug spec/controllers/pages_controller_spec.rb
Run Code Online (Sandbox Code Playgroud)
调试器运行,但会引发以下错误:
> require 'spec_helper'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/kevin/.rvm/bin/rails_projects/evaluationrx/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:125:in `debug_load'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:125:in `debug_program'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:412:in `<top (required)>'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/bin/rdebug:19:in …Run Code Online (Sandbox Code Playgroud) 有没有人知道使用Thin同时运行ruby调试器和SSL的方法?
我一直在使用Rails 3.0.10成功使用Thin.
我开始使用它rails server --debugger,我可以调试我的代码.
最近,我还需要为我的应用程序添加SSL支持,并且我希望能够使用自签名证书在本地测试它.
不幸的是,我还没有找到一种在使用时启动Thin with SSL支持的方法rails server.
我可以使用以下方法成功启动Thin with SSL支持:
thin start --ssl --ssl-verify --ssl-key-file ssllocal/server.key
--ssl-cert-file ssllocal/server.crt
Run Code Online (Sandbox Code Playgroud)
但是,我还没有找到一种方法来激活调试器thin start.
所以我似乎可以选择运行debugger(rails server)或SSL(thin start),但不能同时运行.
似乎可以rails server通过修改rails/script文件让Webrick运行SSL (参见这里).我尝试了这种方法,但我没有成功.这是其中一个尝试:
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3
# gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
# THIS IS NEW: …Run Code Online (Sandbox Code Playgroud) 我有以下型号:
class Evaluation < ActiveRecord::Base
attr_accessible :product_id, :description, :evaluation_institutions_attributes
has_many :evaluation_institutions, :dependent => :destroy
accepts_nested_attributes_for :evaluation_institutions, :reject_if => lambda { |a| a[:token].blank? }, :allow_destroy => true
validate :requires_at_least_one_institution
private
def requires_at_least_one_institution
if evaluation_institution_ids.nil? || evaluation_institution_ids.length == 0
errors.add_to_base("Please select at least one institution")
end
end
end
class EvaluationInstitution < ActiveRecord::Base
attr_accessible :evaluation_institution_departments_attributes, :institution_id
belongs_to :evaluation
has_many :evaluation_institution_departments, :dependent => :destroy
accepts_nested_attributes_for :evaluation_institution_departments, :reject_if => lambda { |a| a[:department_id].blank? }, :allow_destroy => true
validate :requires_at_least_one_department
private
def requires_at_least_one_department
if evaluation_institution_departments.nil? || …Run Code Online (Sandbox Code Playgroud) 我正在为用户注册页面构建测试.我准备将Recaptcha添加到页面中,我不知道如何在rspec中对其进行说明.具体来说,我希望我的集成测试验证用户是否可以填写页面,单击按钮,然后注册.但是在页面上使用Recaptcha,我如何让Rspec模拟输入有效的Recaptcha字符串?
有一段时间没有使用postgres,我在刚开始使用的现有项目中遇到了这个问题.
当我运行时rails g migrate,命令成功完成; 然而,它会产生一大堆差异db/structure.sql.不同之处在于修订后的文件使用postgres公共模式显式地为每个命令添加前缀.
例如,我得到许多像这样的差异:
-CREATE TABLE customer (
+CREATE TABLE public.customer (
我怎么能抑制这种行为?
我在医院表格中有一个针对部门的嵌套模型.代码段如下所示:
<%= f.simple_fields_for :hospital do |h| %>
.
.
.
<%= h.simple_fields_for :departments do |builder| %>
<%= render "department_fields", :f => builder %>
<% end %>
.
.
<% end %>
Run Code Online (Sandbox Code Playgroud)
_department_fields部分看起来像这样:
<div class="fields">
<%= f.input :name %>
<%= link_to_remove_fields "remove", f %>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
因此,表单底部有一个位置供用户输入最多三个部门名称.
我正在使用Rails 3,Cucumber,Capybara和Selenium进行集成测试.
在Cucumber中测试此表单时,是否有一种简单的方法可以填写重复字段?
理想情况下,我希望能够像这样编写我的功能:
And I fill in the first "Name" with "Cardiology"
And I fill in the second "Name" with "Radiology"
Run Code Online (Sandbox Code Playgroud)
有没有办法在Cucumber/Capybara中轻松估算出这个?有人已经找到了解决这个问题的一些步骤吗?
rspec ×3
ruby-debug ×2
backtrace ×1
capybara ×1
cucumber ×1
nested-forms ×1
recaptcha ×1
ssl ×1
thin ×1