testunit

Ruby “test/unit” , how do I display the messages in asserts

邮差的信 提交于 2019-12-11 10:49:11
问题 I have assertions in place in my ruby script. Each of these assertions also has a message to describe the assertion. So I have two questions revolving around this I want the messages associated with each assert to display as the test progresses. Currently the Message only displays when any thing fails The entire test exits when any assertion fails. How do i make the tests continue even if one assertion fails? Sample code that i am using assert_match("hey", "hey this is a test", "The word

Rake is too verbose, echos test command

喜夏-厌秋 提交于 2019-12-11 08:17:24
问题 Rake is too verbose: $ bundle exec rake test:units /Users/jared/.rvm/rubies/ruby-1.8.7-p370/bin/ruby -I"lib:test" -I"/Users/jared/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib" "/Users/jared/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" Loaded suite /Users/jared/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader Started ..................................... This is what I want: $ bundle exec rake

With Test::Unit, how can I run a bit of code before all tests (but not each test)?

旧巷老猫 提交于 2019-12-10 16:26:21
问题 In my test app, which uses test::unit, I need to start by pulling a bunch of data from various sources. I'd like to only do this once - the data is only read, not written, and doesn't change between tests, and the loading (and error checking for the loading), takes some time. There are values that I DO want reset every time, and those are easy enough, but what if I want persistant accessible values? What's the best way to do this? I'm especially interested in solutions that would let my push

Capybara issue: @request must be an ActionDispatch::Request

房东的猫 提交于 2019-12-10 16:01:30
问题 I'm having problems making Capybara work with Rails. Just testing that suposedly interesting test thing. OK, in the attached code there are a couple of equivalent tests. The first one is made with shoulda-context + Test::Unit that comes with Rails. The second test is made with capybara and shoulda-context too. require 'integration_test_helper' class UsersTest < ActionDispatch::IntegrationTest fixtures :all context "signup" do context "failure" do setup do @attr = { :name => "", :email => "",

How do i get RSpec's shared examples like behavior in Ruby Test::Unit?

拟墨画扇 提交于 2019-12-10 12:55:35
问题 Is there a plugin/extension similar to shared_examples in RSpec for Test::Unit tests? 回答1: If you are using rails (or just active_support), use a Concern. require 'active_support/concern' module SharedTests extend ActiveSupport::Concern included do # This way, test name can be a string :) test 'banana banana banana' do assert true end end end If you're not using active_support, just use Module#class_eval . This technique builds on Andy H.'s answer, where he points out that: Test::Unit tests

What is the difference between jest.mock(module) and jest.fn()

你离开我真会死。 提交于 2019-12-09 16:39:32
问题 I have tried couple different ways of defining the mock function and all of my tries failed. When I try to define it as follow: jest.mock('../src/data/server', ()=> ({server: {report: jest.fn()}})); expect(server.report.mock).toBeCalledWith(id, data, () => {...}, () => {...}); I get the this error: expect(jest.fn())[.not].toBeCalledWith() jest.fn() value must be a mock function or spy. Received: undefined If I define the mock as : var spy = jest.mock('../src/data/server', ()=> ({server:

Why 'undefined method `assert_equal' ' is thrown even after requiring 'test/unit'

核能气质少年 提交于 2019-12-09 16:37:14
问题 I opened irb & entered: require 'test/unit' but when I used the assert_equal method, I got following error: NoMethodError: undefined method 'assert_equal' for main:Object . Why is this happening even after requiring 'test/unit' ? 回答1: assert_equal is defined on subclasses of Test::Unit::TestCase , so are only available in that class. You may have some success with include Test::Unit::TestCase to load those methods onto the current scope. More likely you could be better writing your tests in a

Is it still possible to use test-unit in rails 4?

可紊 提交于 2019-12-08 15:48:10
问题 After upgrading from Rails 3.2 to Rails 4, my app works, but my tests, written with test-unit, are a disaster. Minitest is rumored to be "compatible" with test-unit. However, if I attempt to use the (now bundled) Minitest, there are a raft of differences - from the assert* statement names and parameters to (clearly) many other things things both large and subtle. If I instead try to avoid Minitest and attempt to keep my test-unit gem in my Gemfile, rake test explodes, saying, undefined method

Why do Test::Unit testcases start up so slowly?

六眼飞鱼酱① 提交于 2019-12-08 05:36:32
问题 >rails -v Rails 1.2.6 >ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] When I run a test fixture (that tests a rails model class) like this, it takes 20-30 secs to start executing these tests (show the "Loaded suite..."). What gives? >ruby test\unit\category_test.rb require File.dirname(__FILE__) + '/../test_helper' class CategoryTest < Test::Unit::TestCase def setup Category.delete_all end def test_create obCategoryEntry = Category.new({:name=>'Apparel'}) assert obCategoryEntry

how to write and inherit from an abstract subclass of ActionController::TestCase

半世苍凉 提交于 2019-12-06 07:18:26
问题 I have a bunch of Rails 3.1 controllers which all have very similar testing requirements. I have extracted out the common code (all Test::Unit style), e.g. the following three tests are completely reusable across all of them: def create new_record = { field_to_update => new_value } create_params = { :commit => "Create", :record => new_record } post :create, create_params end test "should_not_create_without_login" do assert_no_difference(count_code) do create; end assert_need_to_log_in end