Tag: rspec

RSpec中的相对文件路径

我对/lib/classes的类进行了RSpec测试,需要访问zip文件(无上传)。 该文件存储在/spec/fixtures/files/test.zip 。 如何输入正确的路径以使其与环境无关,即没有绝对路径?

Rails在哪里存储通过在测试期间保存activerecord对象而创建的数据?

Rails在哪里存储通过在测试期间保存activerecord对象而创建的数据? 我以为我知道这个问题的答案:显然在_test数据库中 。 但看起来这不是真的 ! 我使用这个系统来测试在rspec测试期间保存的ActiveRecord数据发生了什么: $ rails -d mysql test $ cd测试 $ nano config / database.yml … …创建mysql数据库test_test,test_development,test_production $ script / generate rspec $ script / generate rspec_model foo 编辑Foo迁移: class CreateFoos $ rake db:migrate 编辑spec / models / foo_spec.rb: 需要File.expand_path(File.dirname(__ FILE__)+’/../spec_helper’) 描述Foo做 之前(:每个)做 @valid_attributes = { :bar => 12345 } 结束 它“应该创建一个给定有效属性的新实例” […]

使用Ruby 1.8.7的标题案例

如何将字符串中的某些字母大写以使其仅使指定的单词大写。 必须通过这些测试:“barack obama”==“Barack Obama”和“黑麦中的守望者”==“麦田里的守望者” 到目前为止,我有一个方法可以将所有单词大写: #Capitalizes the first title of every word. def capitalize(words) words.split(” “).map {|words| words.capitalize}.join(” “) end 我可以采取哪些最有效的后续步骤来达成解决方案? 谢谢!

在每种方法后检测Rspec测试失败

我正在尝试运行RSpec测试,我想在after方法中检测测试是否失败。 我现在有类似的东西: after(:each) do cc = ConnectController.new() cc.update(, , result?) end 如你所见, result? 函数是我需要替换的,检测测试是否失败,以及获取有关失败的测试的信息。

以前可以使用:全部用水豚吗?

我有一个这样的描述块: describe “Documents” do subject { page } let (:course) { FactoryGirl.create(:course) } describe “new” do before do visit new_course_document_path(course) fill_in “Name”, with: “TestDocument” attach_file “Original document”, “#{Rails.root}/spec/fixtures/03_GUI_concurrency.pdf” end it { should have_selector(‘title’, text:”Upload document”)} it { should have_selector(‘h1’, text:”Upload document”)} describe “when clicking upload” do before { click_button “Upload Document” } it “should have […]

Ruby on Rails – ActiveRecord ::关系计数方法错了?

我正在编写一个应用程序,允许用户发送有关“优惠”的消息。 我以为我会节省一些工作并使用Mailboxer gem。 我正在遵循RSpec的测试驱动开发方法。 我正在编写一个测试,确保每个优惠只允许一次Conversation 。 优惠belongs_to两个不同的用户(提出优惠的用户和收到优惠的用户)。 这是我的失败测试: describe “after a message is sent to the same user twice” do before do 2.times { sending_user.message_user_regarding_offer! offer, receiving_user, random_string } end specify { sending_user.mailbox.conversations.count.should == 1 } end 因此,在测试运行之前,用户sending_user向sending_user发送两次消息。 message_user_regarding_offer! 看起来像这样: def message_user_regarding_offer! offer, receiver, body conversation = offer.conversation if conversation.nil? self.send_message(receiver, body, offer.conversation_subject) else self.reply_to_conversation(conversation, […]

为什么我的RSpec测试失败,但我的应用程序正在运行?

我刚刚完成了Ruby on Rails教程的第10章 ,添加了编辑/更新,索引和销毁用户的function。 一切似乎都在我的应用程序中正常工作,但是当我运行RSpec时,我的许多测试都失败了。 我设置的users_controller_spec与书的设置完全一样,我的应用程序代码也是一样的。 一个问题可能是我使用Rails 3.1.1而不是他在书中使用的Rails 3.0? 它对于以前的测试来说并不是一个问题,只是偶尔会出现几行不同的代码。 在我开始第10.2.1节后 ,问题开始出现。 以下是我看到的错误列表,如果您需要更多信息,请告诉我。 谢谢! 1) UsersController GET ‘index’ for signed-in users should be successful Failure/Error: response.should be_success expected success? to return true, got false # ./spec/controllers/users_controller_spec.rb:31:in `block (4 levels) in ‘ 2) UsersController GET ‘index’ for signed-in users should have the right title Failure/Error: response.should […]

如何在rspec测试中定义一个可以由辅助函数接收的简单全局变量

我无法弄清楚如何在rspec测试中使用一个简单的全局变量。 这看起来像是一个微不足道的function,但经过一番戏剧性的努力,我找不到解决方案。 我想要一个可以在主要规范文件和辅助规范文件中的函数中访问/更改的变量。 这是我到目前为止: require_relative ‘spec_helper.rb’ require_relative ‘helpers.rb’ let(:concept0) { ” } describe ‘ICE Testing’ do describe ‘step1’ do it “Populates suggestions correctly” do concept0 = “tg” selectConcept() #in helper file. Sets concept0 to “First Concept” puts concept0 #echos tg?? Should echo “First Concept” end end 。 #helpers.rb def selectConcept concept0 = “First Concept” end […]

黄瓜步骤定义为“鉴于我已登录”

我有一个黄瓜步骤:鉴于我已登录 我不明白我应该如何将其作为步骤定义来实现。 有人能指出我正确的方向,教程,博客等。

使用Rspec测试rake任务不接受参数

根据Stephen Hagemann的这篇文章,我正试图为我的一个rake任务编写一个Rspec测试。 lib/tasks/retry.rake : namespace :retry do task :message, [:message_id] => [:environment] do |t, args| TextMessage.new.resend!(args[:message_id]) end end spec/tasks/retry_spec.rb : require ‘rails_helper’ require ‘rake’ describe ‘retry namespace rake task’ do describe ‘retry:message’ do before do load File.expand_path(“../../../lib/tasks/retry.rake”, __FILE__) Rake::Task.define_task(:environment) end it ‘should call the resend action on the message with the specified message_id’ do message_id […]