Tag: rspec

Gem文件不会使用bundler更新或安装

我正在研究Michael Hartl的RoR教程。 我在第3章。不幸的是,复制和粘贴gem文件对我来说不起作用,但我想出了哪个gem是问题所在。 它是水豚gem。 我已经评论过它并继续教程,但我正处于需要使用gem的地步。 这是一个示例$ bundle update给我一个错误: $ bundle update Fetching gem metadata from https://rubygems.org/……… (Removed a bunch of text) Building nokogiri using system libraries. Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/dbz/.rvm/rubies/ruby-2.0.0-p481/bin/ruby extconf.rb –use-system-libraries Building nokogiri using system libraries. libxml2 version 2.6.21 or later is required! *** extconf.rb failed *** Could not […]

Git:在推送到本地或远程主服务器之前强制执行测试

如果测试(rspec)失败,有没有办法让git拒绝提交本地或推送到远程主设备? 谢谢。

如何rspec模拟ruby rails logger类

嗨我,并尝试rspec模拟以下类: class Person def initialize(personid) Rails.logger.debug “Creating person with id #{personid}” end end 使用这个: require ‘spec_helper’ describe Person do describe “#initialize” do let(:rails_mock) { double(“Rails”).as_null_object } let(:logger_mock) { double(“Rails.logger”).as_null_object } it “logs a message” do rails_mock.stub(:logger).and_return(logger_mock) logger_mock.should_receive(:debug) Person.new “dummy” end end end 并收到此消息: RSpec :: Mocks :: MockExpectationError 🙁 Double“Rails.logger”)。debug(any args) 预计:1次 收到:0次 任何帮助都会很棒!

Rspec – 未定义的方法’let’

这是我的rspec文件: require ‘spec_helper’ describe “Birds” do before { visit birds_path } it “should have the right title” do expect(page).to have_content(“Approved Birds”) end it “should contain the bird’s name, genus, species” do let(:bird) { FactoryGirl.create(:bird) } expect(page).to have_content(“#{bird.name}”) expect(page).to have_content(“#{bird.genus}”) expect(page).to have_content(“#{bird.species}”) end end 当我运行它时,我收到以下错误: Failure/Error: let(:bird) { FactoryGirl.create(:bird) } NoMethodError: undefined method `let’ for # […]

让RSpec报告中间故障

有没有办法让RSpec报告失败,而不是长绿色/红色点列表? 我正在运行RSpec 2.5.0。

RSpec:“should == …”和“should eql(…)”之间的区别

在RSpec中,使用should == …和should eql(…)之间有什么区别? 我注意到RSpec文档总是使用eql ,但==键入的内容更少,更易于阅读。 我错过了什么?

Rspec有(n).items未定义的方法

我正在尝试遵循code.tuts的指南,我一直收到错误。 这是我的图书馆规范: require ‘spec_helper’ describe Library do before :all do lib_arr = [ Book.new(“JavaScript: The Good Parts”, “Douglas Crockford”, :development), Book.new(“Dont Make me Think”, “Steve Krug”, :usability), ] File.open “books.yml”, “w” do |f| f.write YAML::dump lib_arr end end before :each do @lib = Library.new “books.yml” end describe “#new” do context “with no parameters” do it […]

LoadError:无法加载此类文件 – rspec / core / rake_task

更新:这个问题仍未解决! 任何帮助表示赞赏! 05/07/2015 更新:找到了解决方法。 请看我自己的答案05/09/2015 当我耙,我得到了这个错误。 AllenLins-MacBook-Pro:geoblacklight allenlin$ rake -t Resolving dependencies… You must `gem install bundler` and `bundle install` to run rake tasks rake aborted! LoadError: cannot load such file — rspec/core/rake_task /Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in `require’ /Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in `’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile’ /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run’ […]

在rspec中描述vs context。 区别在哪里?

我已经阅读了一些关于如何组织rspec代码的内容。 似乎“上下文”更多地用于对象的状态。 用你的话来说,你如何描述如何在rspec代码中使用“describe”? 这是我的movie_spec.rb代码的片段: require_relative ‘movie’ describe Movie do before do @initial_rank = 10 @movie = Movie.new(“goonies”, @initial_rank) end it “has a capitalied title” do expect(@movie.title) == “Goonies” end it “has a string representation” do expect(@movie.to_s).to eq(“Goonies has a rank of 10”) end it “decreases rank by 1 when given a thumbs down” do @movie.thumbs_down […]

Rails:为什么RSpec会崩溃我的被覆盖的Devise控制器请求规范?

更新:哦,好悲伤,这是一个糟糕的合并后的红鲱鱼。 沿着这条线的某个地方,以下内容从spec / spechelper.rb的清理中删除 Dir[“#{Rails.root}/app/**/*.rb”].each {|f| load f} 现在这已经恢复,一切都在恢复。 我怀疑它只是加载平面目录,而不是嵌套目录,使它看起来像命名空间问题。 (我不能回答我自己的问题,因为这是一个新帐户,我没有代表) 原始问题: 我的大多数RSpec / Capybara测试工作正常,但我有一个测试只是试图访问路径爆炸,我坚持调试。 我怀疑这是一个命名空间问题,但我不知道如何解决这个问题; 任何帮助感激不尽。 整个测试是: require ‘spec_helper’ describe ‘Registrations’ do context ‘when debugging the blocking issue’ do it ‘this minimal test should pass’ do visit new_user_registration_path end end end 错误消息是: $ bin / rspec spec / requests / users / registrations_spec.rb 失败: […]