Tag: rspec

“Rake spec”在大多数测试中失败,但“rails s”在Diaspora源上工作正常

我有克隆的Diaspora来源,我有一个工作的本地吊舱似乎顺利运行。 但是当我运行$ rake spec一些初始测试通过,然后所有这些都开始失败。 此外,我发现有趣的是,每次运行rake spec时它们都会在不同的点上失败。 他们都失败了,错误: An error occurred in an after hook ActiveRecord::StatementInvalid: PG::ConnectionBad: PQsocket() can’t get socket descriptor: ROLLBACK occurred at /home/darshan/.rvm/gems/ruby-2.0.0-p353@diaspora/gems/activerecord-3.2.16/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec’ Postgres的日志说: could not receive data from client: Connection reset by peer unexpected EOF on client connection

使用Minitest测试控制器

我正在尝试使用Minitest找到测试控制器的示例,但我只发现了一对,只是validation了呈现的模板以及返回的“成功”。 这对我来说似乎没什么帮助。 Minitest用于测试控制器吗? Railscast( http://railscasts.com/episodes/327-minitest-with-rails )以及我发现的其他几篇文章似乎都在使用Minitest进行模型测试,并与Capybara进行集成测试。 控制器测试怎么样? 他们可以用Minitest测试吗? 如果是这样,是否有任何实际测试操作的真实示例? 在经过几个小时的搜索之后,我找不到任何东西似乎很奇怪。 我知道这很模糊,但是我想决定是否应该使用RSpec或Minitest,但是如果不知道如何使用Minitest真正测试控制器,我不知道它是如何真正的选择,但我继续阅读一些关于它的一般好评如潮。

rubyMine’无法将测试报告者附加到测试框架’

运行所有模型测试时,检测到rubyMine’MiniTest框架’错误。 我可以在常规命令行运行所有模型测试。 例如rake spec:models 当我使用rubyMine时: 我可以运行一个模型测试。 但是,当我尝试在模型中运行所有测试时,我得到了 MiniTest framework was detected. It is a limited version of original Test::Unit framework. RubyMine/IDEA Ruby plugin test runner requires full-featured version of the framework, otherwise default console tests reporter will be used instead. Please install ‘test-unit’ gem and activate it on runtime. 我尝试将’test-unit’添加到我的Gemfile并重新绑定,但现在得到: `/home/durrantm/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/durrantm/Downloads/RubyMine-3.2.3/rb/testing/runner/tunit_in_folder_runner.rb Testing […]

使用Rspec和Rack :: Test测试REST-API响应

我有点难过。 我有以下集成测试: require “spec_helper” describe “/foods”, :type => :api do include Rack::Test::Methods let(:current_user) { create_user! } let(:host) { “http://www.example.com” } before do login(current_user) @food = FactoryGirl.create_list(:food, 10, :user => current_user) end context “viewing all foods owned by user” do it “as JSON” do get “/foods”, :format => :json foods_json = current_user.foods.to_json last_response.body.should eql(foods_json) last_response.status.should eql(200) […]

SimpleCov计算用户模型的0%覆盖率

我决定尝试使用simplecov gem。 我认为这是很酷的工具,但我有一个问题: 我有模型用户,我有user_spec.rb,其中包含测试用例,但simplecov显示该模型的0%覆盖率。 它显示其他模型的100%覆盖率,这是真的。 我不明白User模型有什么问题。 class User < ActiveRecord::Base extend Enumerize # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable STATUS_ACTIVE = :active STATUS_BANNED = :banned enumerize :status, in: [STATUS_ACTIVE, STATUS_BANNED], default: STATUS_ACTIVE with_options inverse_of: :user, dependent: :destroy do has_one :profile has_many […]

Rspec:2级嵌套资源的控制器规范

我的routes.rb namespace :magazine do resources :pages do resources :articles do resources :comments end end end 在为评论编写控制器规范时: describe “GET ‘index'” do before(:each) do @user = FactoryGirl.create(:user) @page = FactoryGirl.build(:page) @page.creator = @user @page.save @article = FactoryGirl.create(:article) @comment_attributes = FactoryGirl.attributes_for(:comment, :article_id => @article ) end it “populates an array of materials” do get :index, ?? #response.should be_success […]

我可以使用RSpec测试已部署的站点吗?

我应该首先说,我不是很精通测试我的代码,直到最近我才完全没有这样做。 所以我有这个rails应用程序。 它基本上是一个API端点。 它需要请求并吐出JSON。 有很好的(我希望)测试覆盖率应该测试大多数function。 现在我们正在部署一个staging env,并希望让负载测试人员(独立部门)与之“玩”。 我想确定我们是否正确部署了它。 我是否可以针对此暂存部署运行RSpec的请求规范? 人们会做这种测试吗? 什么是最佳做法? 我该怎么读?

Capybara没有找到元标签

Capybara 2.1.0似乎没有找到任何元标记: (rdb:1) p page.find ‘meta’ *** Capybara::ElementNotFound Exception: Unable to find css “meta” 即使它们出现在page.source : (rdb:1) p page.source “\n\n\nMyTitle\n\n\n\n\n\n…”

Capybara NoMethodError:未定义的方法`visit’for

感谢回复。 我在应用程序Git应用程序中收到错误错误 Failures: 1) Page pages page creation with invalid information should not create a page Failure/Error: before(:each) { visit new_admin_page_path } NoMethodError: undefined method `visit’ for # # ./spec/requests/page_request_spec.rb:13:in `block (3 levels) in ‘ 2) Page pages page creation with invalid information error messages Failure/Error: before(:each) { visit new_admin_page_path } NoMethodError: undefined method `visit’ […]

Rails / Devise – 我应该用devise和rspec测试什么?

许多程序员使用devise作为他们的身份validation解决方案,我想得到他们的建议: Devise已经过测试,但是我想知道是否有自己需要测试的东西(集成/单元/function测试?)与我的知识进行标准设计集成(我不熟悉shoulda和黄瓜,但我知道rspec和工厂女孩的一点) 谢谢你的建议!!