Tag: rspec

在Rails中禁用unit testing生成器

有谁知道如何禁用Rails中的自动unit testing文件生成? 无论何时创建控制器,模型或迁移,它都会在test /目录中创建关联文件; 我需要这个禁用。 此外,是否可以使RPsec接管,以便在执行标准rails g model | controller | migration命令时使用RSpec(在spec /目录中)创建文件?

Rails Rspec错误 – 未定义的方法`访问’

所以我是TDD的新手,我在我的测试中抛出一些Rspec错误…基本上在运行bundle exec rspec spec之后,我得到一些undefined method ‘visit’错误我的一些规范。 任何有关如何通过这些测试的帮助将非常感激:谢谢。 Failures: 1) User pages profile page Failure/Error: before { visit user_path(user) } NoMethodError: undefined method `visit’ for # # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in ‘ 2) User pages profile page Failure/Error: before { visit user_path(user) } NoMethodError: undefined method `visit’ for # # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in […]

Rspec和Rails 4,更新跳过回调

我尝试使用rspec为我的rails应用程序运行更新测试。 我正在使用rspec 3.5和rails 4。 行为应该是以下内容: 当我以销售价格创建新服务时,它会创建一个Price实例并设置与服务的关系。 然后,当我更新我的服务时,如果没有售价,则会破坏价格记录(客户要求节省数据库中的空间)。 我实施的过程似乎工作正常,当我用UI测试并且我检查价格记录的数量时,它会像它假设的那样减少一个。 但是,unit testing是否失败。 这是代码: 服务控制器: def update @service.assign_attributes(service_params) puts “update method” respond_to do |format| if @service.valid? if params[‘preview’] @service.build_previews format.js { render ‘services/preview’ } else @service.save! format.html { redirect_to client_trip_days_path(@client, @trip), notice: t(‘flash.services.update.notice’) } end else format.html { render :edit } format.js { render :new } end end […]

ArgumentError:工厂未注册

我试图让工厂女孩在我的rails 4.1.1应用程序中使用rspec运行。 问题是当我在命令行中运行rspec时,我得到Failure/Error: verse = build(:verse) ArgumentError: Factory not registered: verse 。 我很茫然,因为我检查了工厂女孩入门页面,这里有许多答案,我仍然无法解决这个问题。 在我的Gemfile中: gem ‘rails’, ‘4.1.1’ group :development, :test do gem ‘rspec-rails’ gem “factory_girl_rails” end 我的spec_helper.rb文件: require ‘factory_girl_rails’ RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods end 规格/控制器/ API / verses_controller_spec.rb describe “API Controller” do describe “show a verse” do it “should return status 200” do verse […]

为什么我的Capybara / Poltergeist测试不能从jQuery自动完成字段中选择?

更新:经过我自己的大量艰苦工作后,我解决了这个问题。 我很高兴成为任何需要帮助的人的资源。 这是我工作设置的要点。 我已经尝试了所有可以找到Google和SO的解决方案。 以下是我尝试过的一些不同的事情: page.execute_script %Q{$(‘#{selector}’).val(‘#{value}’).trigger(‘keydown’)} 和 fill_in field, with: options[:with] page.execute_script %Q{ $(‘##{field}’).trigger(‘focus’) } page.execute_script %Q{ $(‘##{field}’).trigger(‘keydown’) } 这是失败的: page.should have_selector(‘ul.ui-autocomplete li.ui-menu-item a’) 但是当我在Firebug中查看并在浏览器中测试它时,它肯定存在。 以下是所有细节,包括上述内容的重述。 请记住,自动填充字段在浏览器中正常工作。 listing_integration_spec.rb require “spec_helper” describe “Listing Integration” do let!(:user) { login_user } it “lets a user add information listing”, js: true do listing = create(:listing, user: user) click_link(‘Additional […]

不兼容的库版本:nokogiri.bundle需要11.0.0或更高版本,但libxml2.2.dylib

我试图在Hartl的教程中运行rspec时遇到此错误。 我搜索了错误,但它从来没有针对特定版本,修复程序实际上并没有解决我的问题。 /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri.rb:28:in `require’: dlopen(/Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri- 1.6.0/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /Users/Jimbo/.bundler/tmp/22862/gems/nokogiri-1.6.0/ports/i686-apple- darwin11/libxml2/2.8.0/lib/libxml2.2.dylib (LoadError) Referenced from: /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri- 1.6.0/lib/nokogiri/nokogiri.bundle Reason: Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0 – /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri/nokogiri.bundle from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri.rb:28:in `’ from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara.rb:2:in `require’ from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara.rb:2:in `’ from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require’ from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require’ from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in […]

在rails 3.1上,Rspec中的Cookie不会存在

这是以下环境中控制器规范中的cookie集合的问题: rails 3.1.0.rc4 rspec 2.6.0 rspec-rails 2.6.1 我有一个简单的控制器规范,它创建一个Factory用户,调用一个设置cookie的登录方法,然后测试以查看登录用户是否可以访问页面。 问题是所有cookie似乎都在设置的身份validationcookie和我的控制器上调用的“show”操作之间消失。 在rails dev服务器上的浏览器中运行时,我的代码工作正常。 运行规范时更奇怪的行为是,通过cookie哈希设置的所有内容都会消失,但通过会话哈希设置的所有内容都会持续存在。 我只是错过了使用rspec时cookie的工作方式吗? 规格代码 it “should be successful” do @user = Factory(:user) test_sign_in @user get :show, :id => @user response.should be_success end 登录代码 def sign_in(user, opts = {}) if opts[:remember] == true cookies.permanent[:auth_token] = user.auth_token else cookies[:auth_token] = user.auth_token end session[:foo] = “bar” cookies[“blah”] = […]

如何在Rails 3中使用Capybara从选择框中选择日期?

我正在使用RSpec和Capybara为Rails 3项目中的控制器编写规范,我想从选择框中选择当前日期。 我试过了: select Date.today, :from => ‘Date of birth’ 但规格失败了,我得到错误: 失败/错误:选择Date.today,:from =>’出生日期’NoMethodError:未定义的方法`to_xpath’for Mon,2011年7月18日:日期 怎么解决? PS在视图文件中我使用simple_form_for标记,选择框由代码生成: f.input :date_of_birth

关于current_path对象,Rspec和capybara,visit和get方法之间的区别

我可能在这里混淆机架和水豚方法 let!(:admin){FactoryGirl.create(:admin)} # test passes describe “visiting #edit page” do before { visit edit_user_path(admin) } specify { current_path.should eq(edit_user_path(admin)) } end # test fails describe “getting #edit page” do before { get edit_user_path(admin) } specify { current_path.should eq(edit_user_path(admin)) } end 第二次测试失败了: Failure/Error: specify { current_path.should eq(edit_user_path(admin)) } expected: “/users/51/edit” got: “/users/51” (compared using ==) 在before(:each)块之前,将current_path设置为/users/51 […]

试图引发ArgumentError rspec

我有一个没有通过的Rspec测试,我不明白为什么。 所有其他测试都在通过,除了需要ArgumentError 测试看起来像这样: describe “#evaluate” do it “raises error” do expect(rpn.evaluate(‘%’)).to raise_error(ArgumentError) end end 并且我的文件已设置好,因此会引发错误(作为else语句) else raise ArgumentError.new end 但是rspec告诉我这个 Failure/Error: expect(rpn.evaluate(‘%’)).to raise_error(ArgumentError) ArgumentError: ArgumentError