Tag: rspec2

使用水豚时路径不能正常工作

我正在使用rails 3.0.5,rspec2和最新的capybara。 路线设置如下: scope “(:locale)”, :locale => /de|fr|it|en/ do resources :dossiers end 在application_controller我有这个: def default_url_options(options={}) options[:locale] = “es” options end 所以在我看来我可以使用 link_to ‘test’, dossier_path(1) 没有任何问题。 但是当我在capybara的访问中做同样的事情时,它会尝试使用1作为语言环境而不是id。 它只在我使用时才有效 visit dossier_path(nil, 1) 要么 visit dossier_path(:id => 1) 但两者都是丑陋的,看起来像一个肮脏的黑客。 那么为什么我需要使用这个脏的hack以及我要做什么,以便我可以像在视图中一样使用路径方法(所以没有必须添加nil或显式传递的脏黑客:id =>。 ..)? 🙂

运行我的控制器的rspec测试时出现Rspec错误

我正在开发一个Rails v2.3应用程序。 当我通过执行命令运行rspec测试时: rspec spec/controllers/my_controller_spec.rb 我收到了以下错误消息 : /.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded’: (RuntimeError) ******************************************************************************** You are running rspec-2, but it seems as though rspec-1 has been loaded as well. This is likely due to a statement like this somewhere in the specs: require ‘spec’ Please locate that statement, remove it, and try again. ******************************************************************************** /.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:420:in `load_spec_files’ —-更新— 因为它抱怨某些包含代码的文件require […]

在辅助规范中存储控制器辅助方法

在我的application_controller.rb : helper_method :current_brand def current_brand @brand ||= Brand.find_by_organization_id(current_user.organization_id) end 在我的帮助者something_helper.rb def brands return [] unless can? :read, Brand # current_brand is called end 我正在为something_helper编写一个规范,并希望将stub_brand存根 describe SomethingHelper do before :each do helper.stub!(:can?).and_return(true) # This stub works end it “does the extraordinary” do brand = Factory.create(:brand) helper.stub!(:current_brand).and_return(brand) # This stub doesnt work helper.brands.should_not be_empty end end […]

spec with guard,rails 3.1.1和ruby 1.9.3获取无法加载此类文件错误

我刚刚在macbook air上安装了rvm和所有好东西,我用ruby 1.9.3启动了我的rails 3.1.1应用程序。 在我的gem文件中,我放下了警卫和rspec,现在当我尝试单独运行rspec或使用警卫时,我会向我发出错误并且我不确定为什么, 我运行时得到的输出是这样的, phantom:tasks maxmarze$ guard Please install rb-fsevent gem for Mac OSX FSEvents support Using polling (Please help us to support your system better than that). Please install growl_notify or growl gem for Mac OS X notification support and add it to your Gemfile Guard is now watching at ‘/Users/maxmarze/rails_projects/tasks’ Guard::RSpec […]

Object.save在规范数据validation中失败

以下是客户控制器中创建的失败规范代码: describe CustomersController do before(:each) do #the following recognizes that there is a before filter without execution of it. controller.should_receive(:require_signin) controller.should_receive(:require_employee) end render_views describe “‘create’ successful” do before(:each) do category = Factory(:category) sales = Factory(:user) @customer = Factory.attributes_for(:customer, :category1_id => category.id, :sales_id => sales.id) session[:sales] = true session[:user_id] = sales.id session[:user_name] = sales.name session[:page_step] = […]

黄瓜和自定义RSpec匹配器

我正在尝试为黄瓜编写一个自定义RSpec匹配器。 我在env.rb中需要cucumber / rails / rspec,但我仍然得到“未初始化的常量Spec :: Matchers”错误。 我正在使用最新版本的Rspec,Cucumber和CucumberRails。 我错过了什么? PS相同的匹配器与纯RSpec一起工作正常…

Rspec没有路线匹配

我在rspec中遇到以下错误: 1) LandingController landing#index returns http success Failure/Error: get :index ActionController::RoutingError: No route matches {:controller=>”landing”} # ./spec/controllers/landing_controller_spec.rb:7:in `block (3 levels) in ‘ 这是考验 require ‘spec_helper’ describe LandingController do describe “landing#index” do it “returns http success” do get :index response.should be_success end end end 我以root :to => ‘landing#index’ 。 所有其他测试都在通过,只有这一个失败,有人可以帮助我理解为什么吗? 为了完整性,这是rake routes的输出 root / landing#index auth_google_oauth2_callback […]

如何“以编程方式”“迭代地”将每个类对象属性设置为一个值?

我正在使用Ruby on Rails 3.0.9和RSpec 2.我试图以下面的方式重构一些spec文件(为了测试更少的代码类似的类对象属性值): [ :attribute_a, :attribute_b, :attribute_c ].each do |attr| before do # HERE I would like to set the “current” ‘attr’ related to the # class object instance ‘attribute_’ (read below for # more information) each time the iterator is called (note: all # following attributes are NOT attr_accesible – for that […]

Rails 3.2.1:在视图中调用未定义的方法会导致测试挂起30秒以上

我正在将我的应用程序从3.0.9升级到3.2.1(ruby 1.9.3-p0,rvm,bundler),还有一件我无法追踪的问题就是这个问题。 我有一个控制器规范(在规格/控制器中)为每个示例呈现视图。 它呈现的模板可以有任何未定义的方法(比如在haml中调用“ – blahblah”),它会导致测试挂起超过30秒。 这是错误: undefined local variable or method `blahblahblah’ for #<#:0x007fa849c578c8> 我运行调试器并在尝试记录错误本身时发生了挂起。 这发生在activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb line 22 。 这个Rails的错,haml的错,还是其他一些库? 这是我的Gemfile,以防我使用的东西可能是问题: source ‘http://rubygems.org’ source ‘http://gems.github.com’ source ‘http://gemcutter.org’ gem ‘rails’, ‘3.2.1’ gem ‘rake’, ‘~> 0.9.2.2’ gem ‘mysql2’, ‘~> 0.3.11’ gem ‘htmldoc’ gem ‘haml’, ‘~> 3.1.4’ gem ‘sass’, ‘~> 3.1.4’ gem ‘hpricot’ gem ‘curb’ gem ‘mini_magick’ […]

RSpec Rails登录filter

我最近开始使用我的Rails(3.0.8)应用程序使用rspec-rails(2.6.1)。 我已经习惯了Test :: Unit,而且我似乎无法为我的测试方法提供filter。 我喜欢尽可能保持DRY,所以我想设置一个filter,我可以在调用测试方法之前调用任何将作为Authlogic用户登录的测试方法。 我尝试使用spec_helper.rb中的RSpecfilter来完成此操作: config.before(:each, :login_as_admin => true) do post “/user_sessions/create”, :user_session => {:username => “admin”, :password => “admin”} end 然后我在相应的测试方法中使用它(在本例中为spec / controllers / admin_controller_spec.rb): require ‘spec_helper’ describe AdminController do describe “GET index” do it(“gives a 200 response when visited as an admin”, :login_as_admin => true) do get :index response.code.should eq(“200”) end end […]