minitest

Acceptance testing of sinatra app using webrat fails

痴心易碎 提交于 2019-12-25 05:16:27
问题 I am trying to test a ruby authentication app using minitest and webrat but get errors. Tests like visit '/' fail with an error Status 200 expected but was 404. Tests containing code like fill_in :email, :with => "first@company.com" fail with error Could not find field: :email . I read several sinatra, testing and webrat documents and forums. Some of them were old and suggested stuff like Sinatra::Default, but github.com/brynary/webrat/wiki/sinatra, Building a Sinatra App Driven By Webrat

How do I test (TDD) a singleton class?

﹥>﹥吖頭↗ 提交于 2019-12-24 03:24:04
问题 I am starting with DDD and TDD in a Ruby application using Minitest. I created a repository class (no database access, but it generates the entities for me). It is a singleton. I would like to test the generation of the entities. The problem is that because it is a singleton, the order of executions of the tests affect the results. Is there any way to force the disposal of the singleton element so it is "fresh"? Here is my repository code: require "singleton" class ParticipantRepository

ruby - how to use tags within examples for minitest

試著忘記壹切 提交于 2019-12-24 01:13:05
问题 I have require 'minitest/spec' require 'minitest/autorun' require 'minitest/tags' require 'rspec/expectations' describe "One happy and one sad test", :happy do include RSpec::Matchers it "it is true" do expect(true).to be true end it "it is false" do expect(false).to be true end end and the describe tag works but I can't add a tag to the it , as in it "it is true", :happy do expect(true).to be true end without getting: $ ruby test_example.rb ...1: from test_example.rb:9:in `block in <main>' .

Testing custom validators with Minitest

守給你的承諾、 提交于 2019-12-23 18:59:00
问题 I have multiple models with email validation. Therefore I've extracted the validation into a custom validator. I dit this by following the tutorial of the Rails Guides. class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i record.errors[attribute] << (options[:message] || "is not an email") end end end So far, so good. But since I've extracted the functionality of email validation into it's

Method expectations in MiniTest

只谈情不闲聊 提交于 2019-12-23 17:45:08
问题 I'm trying to write a test for ActiveRecord - and Rails uses MiniTest for its tests, so I don't have a choice of test framework. The condition I want to test is this (from the db:create rake tasks, pulled into a method for the purpose of this example): def create_db if File.exist?(config['database']) $stderr.puts "#{config['database']} already exists" end end So, I want to test that $stderr receives puts if the File exists, but otherwise does not. In RSpec, I would have done this: File.stub

Testing User Model (Devise Authentication) with MiniTest

 ̄綄美尐妖づ 提交于 2019-12-21 22:38:38
问题 I'm trying to test user model, for which I've devise authentication. The problem I'm facing is, 1. Having 'password'/'password_confirmation' fields in fixtures is giving me invalid column 'password'/'password_confirmation' error. If I remove these columns from fixture and add in user_test.rb require 'test_helper' class UserTest < ActiveSupport::TestCase def setup @user = User.new(name: "example user", email: "example@example.com", password: "Test123", work_number: '1234567890', cell_number:

How do I mock a Class with Ruby?

我的未来我决定 提交于 2019-12-21 15:09:45
问题 I'm using minitest/mock and would like to mock a class. I'm not trying to test the model class itself, but rather trying to test that a service (SomeService) interacts with the model (SomeModel). I came up with this (Hack::ClassDelegate), but I'm not convinced it's a good idea: require 'minitest/autorun' require 'minitest/mock' module Hack class ClassDelegate def self.set_delegate(delegate); @@delegate = delegate; end def self.method_missing(sym, *args, &block) @@delegate.method_missing(sym,

can't get test unit startup to work in ruby 1.9.2

ぃ、小莉子 提交于 2019-12-21 15:04:08
问题 I am using Ruby 1.9.2 (ruby -v yields :ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]), and I am trying to get this to work: require 'test/unit' class TestStartup < Test::Unit::TestCase def self.startup puts "startup" end def test1 puts "in test1" end end when I run it, I get Loaded suite test_startup Started in test1 . Finished in 0.000395 seconds. 1 tests, 0 assertions, 0 failures, 0 errors, 0 skips I had a hard time finding documentation on this feature, other than scattered

can't get test unit startup to work in ruby 1.9.2

自古美人都是妖i 提交于 2019-12-21 15:03:31
问题 I am using Ruby 1.9.2 (ruby -v yields :ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]), and I am trying to get this to work: require 'test/unit' class TestStartup < Test::Unit::TestCase def self.startup puts "startup" end def test1 puts "in test1" end end when I run it, I get Loaded suite test_startup Started in test1 . Finished in 0.000395 seconds. 1 tests, 0 assertions, 0 failures, 0 errors, 0 skips I had a hard time finding documentation on this feature, other than scattered

Why is guard stopping?

﹥>﹥吖頭↗ 提交于 2019-12-20 23:24:35
问题 I have a rails application that I just threw guard and minitest and my gaurd file is guard 'minitest', :cli => '--drb --format doc --color' do # with Minitest::Unit watch(%r|^test/(.*)\/?test_(.*)\.rb|) watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" } watch(%r|^test/test_helper\.rb|) { "test" } # Rails watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" } watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" } watch(%r|^app/models/