Tag: rspec

预期#count已经改变了1,但没有给出阻止

我正在测试我的model方法,它返回一个Account object 。 我正在检查我的表是否插入了一个新row ,我的模型反映了它的计数。 以下是我的规格。 it “can create an account” do create_account = Account.create(account: acc) create_account.should change(Account, :count).by(1); end 我得到的错误 8) Account can create an account Failure/Error: create_account.should change(Account, :count).by(1); expected #count to have changed by 1, but was not given a block

ruby on rails教程第3.2节rspec测试错误

最近由Michael Hartl开始了RoRTute,在第3.2节中尝试了我的第一次rspec测试,此时测试意味着失败,但我得到的都是错误,我很难解释。 我已经环顾四周,但没有找到类似的错误和/或解决方案。 我是编程和ruby / rails的新手。 非常感谢任何帮助,谢谢! 终端错误输出 Macintosh:sample_app rails$ bundle exec rspec spec/requests/static_pages_spec.rb /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `require’: cannot load such file — zip/zip (LoadError) from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common.rb:9:in `require’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common.rb:9:in `’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver.rb:29:in `require’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver.rb:29:in `’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium-webdriver.rb:1:in `require’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium-webdriver.rb:1:in `’ from /Users/rails/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require’ from /Users/rails/.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 […]

如何使用Rspec测试使用Paperclip的模型是否validation上传文件的大小?

该模型: class Attachment true, :size => {:less_than => 20.megabytes} end 测试不起作用: describe Attachment do it { should validate_presence_of :file } it { should validate_size_of :file } # validate_size_of does not exist end 我想避免将20 MB文件转储到repo中来测试它。 有没有一种方法类似于我上面尝试过的实际工作方式?

RSpec升级到OSX Lion后停止工作

dyld: Library not loaded: /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libclparser.dylib Referenced from: /opt/local/bin/identify Reason: image not found 有没有人有办法解决吗? 将Xcode升级到4.1有帮助吗?

Rails 4内存分析

我需要分析rails 4应用程序的内存使用情况(使用ruby MRI)。 一点谷歌搜索让我进入http://guides.rubyonrails.org/v3.2.13/performance_testing.html 我有两个问题: 它与导轨4兼容吗? 我正在使用rspec。 似乎我的rake test品尝不可用( rails generator performance_test )。 当我输入rake test:profile ,我收到了Don’t know how to build task ‘test:profile’ 。 有人知道如何解决这个问题吗? 在此先感谢您的帮助。

使用rSpec测试delayed_job链的最佳方法是什么?

目前我的代码中有一个延迟方法,如下所示: CommentMailer.delay.deliver_comments(@comment, true) 我在我的规范中写了这样的东西: dj = mock(“DelayProxy”) CommentMailer.should_receive(:delay).and_return(dj) dj.should_receive(:deliver_comments).with(comment, true) 是否有更好的方法来处理这种和/或链式方法,例如rSpec中的方法?

不区分大小写的Rspec匹配

我正在编写Capybara测试并使用Rspec进行断言。 我的测试失败了,因为正在应用的CSS样式导致文本全部大写。 我怎样才能重写这个,这是一个不区分大小写的断言? “ALL CAPS”.should include(‘All Caps’)

Rails 3.1 Rspec为Model创建测试用例validation字段

我正在尝试为User模型创建一个测试用例。 基本上,它将validationfirst_name和last_name是否存在。 我要做的是检查特定字段上的错误是否为空,它应该为空。 然而它总是失败。 这样做的正确方法是什么? 这是我的代码 在我的user_spec.rb上 require ‘spec_helper’ describe User do before do @user = User.new end it “must have a first name” do @user.errors[:first_name].should_not be_empty end it “must have a last name” do @user.errors[:last_name].should_not be_empty end end 在我的user.rb文件上 class User true validates :last_name, :presence => true end

使用RSpec和Ruby on Rails的国际字符

我刚刚开始使用RSpec,我在RSpec github repo上复制了非常简单的测试,以确保事情按预期工作: require ‘spec_helper’ describe ‘Home Page’ do it “Welcomes the user” do visit ‘/products’ page.should have_content(“Welcome”) end end 当我将字符串更改为“Olá”或“Caçamba”之类的问题时,问题就开始了。 任何具有特殊字符的字符串。 当我这样做时,我收到以下错误: invalid multibyte char (US-ASCII) (SyntaxError) invalid multibyte char (US-ASCII) syntax error, unexpected $end, expecting ‘)’ page.should have_content(“Olá”) 关于如何修复它的任何想法? 也许一些配置选项? 非常感谢

如何使用Rspec在Sinatra中测试助手块?

我正在编写一个sinatra应用程序并使用rspec和rack / test进行测试(如sinatrarb.com所述)。 到目前为止,它一直很棒,直到我将一些相当程序性的代码从我的域对象移动到sinatra助手。 从那时起,我一直在试图弄清楚如何孤立地测试这些?