minitest

How can I overriding class with proc and yield in test on rails?

空扰寡人 提交于 2019-12-11 10:15:26
问题 I have below classes(only for example), class Background def self.add_thread(&blcok) Thread.new do yield ActiveRecord::Base.connection.close end end end class Email def send_email_in_other_thread Background.add_thread do send_email end end def send_email UserMailer.greeting_email.deliver_now end end And below codes are for tests, class EmailTest < ActiveSupport::TestCase class Background def self.add_thread(&block) yield end end test 'should send email' do assert_difference 'ActionMailer:

Minitest - A test suite with method-level granularity

假如想象 提交于 2019-12-11 09:07:20
问题 After an upgrade, I'm finding the same several test methods failing, so I'd like to automate testing just those instead of all methods in all classes. I want to list each class-method pair (e.g. TestBlogPosts.test_publish , TestUsers.test_signup ) and have them run together as a test suite. Either in a file or on the command-line, I don't really care. I'm aware of these techniques to run several entire classes, but I'm looking for finer granularity here. (Similar to what -n /pattern/ does on

Multiple tests with minitest

只谈情不闲聊 提交于 2019-12-11 08:46:06
问题 I have an app with some specs written into minitest. As usual, I start them using rake . Because some times I got a random results, my specs can pass one time, and fail an other time. In this case, I can keep the sequence number and replay it later, after fixing. Because I have this kind of tests (with a random result), I generally run rake many time, just to be sure that the app is okay. I would like to know if there is a nice way to perform multiple rake tests (100 times for example), and

NoMethodError: undefined method `assert_equal' with minitest

放肆的年华 提交于 2019-12-11 06:31:59
问题 I have testing structure below for automation testing. #/project/class/Calculator.rb require 'TestModule' require 'MathOperation' class Calculator include TestModule include MathOperation def initialize(num1, num2) @num1 = num1 @num2 = num2 end end #/project/methods/MathOperation.rb module MathOperation def operation_addition addition = @num1 + @num2 return addition end end #/project/methods/TestModule.rb module TestModule def test_addition(value) assert_equal 25, value end end #/project

How to test SessionsController for OmniAuth with Minitest

☆樱花仙子☆ 提交于 2019-12-11 02:44:09
问题 I'm trying to test my facebook login code with Minitest, but it's not going well. When I try get :auth, 'provider' => 'facebook' in test, test returns undefined method '[]' for nil:NilClass , and if I try get :new it passes, but auth is not called. How can I successfully get redirected to auth with omniauth? Here's my source code. test/controllers/sessions_controller_test.rb require 'test_helper' class SessionsControllerTest < ActionController::TestCase test '#signup_success' do OmniAuth

EOFError, what happen to my minitest selenium test? how to fix it?

大城市里の小女人 提交于 2019-12-11 01:45:17
问题 After my ubuntu updates, my minitest selenium test got an error, saying: EOFError: EOFError: end of file reached and it opens many blank google chrome windows as feature test total count . my Ubuntu 16.04 updates was ( yesterday everything works fine until the system made an update ): Commandline: aptdaemon role='role-commit-packages' sender=':1.105' Upgrade: snap-confine:amd64 (1.0.42-0ubuntu3~16.04.1, 1.0.43-0ubuntu1~16.04.1), google-chrome-stable:amd64 (53.0.2785.143-1, 54.0.2840.59-1),

minitest: undefined method `get'

做~自己de王妃 提交于 2019-12-10 17:49:09
问题 I'm need to test my controller with minitest. I've tried: describe 'CommentsController' do it "should get index" do get :index assert_response :success end end and class CommentsControllerTest < MiniTest::Unit::TestCase def test_should_get_index get :index assert_response :success end end but I have "undefined method `get'" error 回答1: You should add the minitest-rails gem, following the steps outlined in the documentation. Then your tests should look like this: require "minitest_helper"

With Rails using Minitest, how can I set up RuboCop to run automatically each time tests are run with rake?

谁都会走 提交于 2019-12-10 15:14:36
问题 When I run the following command, I want RuboCop to inspect application directories I specify before tests run: bundle exec rake test 回答1: I added the following task to lib/tasks/test.rake : require 'rubocop/rake_task' # Add additional test suite definitions to the default test task here namespace :test do desc 'Runs RuboCop on specified directories' RuboCop::RakeTask.new(:rubocop) do |task| # Dirs: app, lib, test task.patterns = ['app/**/*.rb', 'lib/**/*.rb', 'test/**/*.rb'] # Make it easier

Expected response to be a <redirect>, but was <200>

心不动则不痛 提交于 2019-12-10 15:09:46
问题 I'm trying to testing the create action in the UsersController where the user is created with a profile; then the user is redirected to the user's profile page, but i get the error Expected response to be a <redirect>, but was <200> . CREATE ACTION IN USER CONTROLLER def create @user = User.new(user_params) if @user.save log_in @user flash[:success] = "Welcome to the Mini Olympics" redirect_to user_profile_path(current_user, @profile) else render 'new' end end SIGNUP TEST USING VALID

How can I test logger-messages with MiniTest?

﹥>﹥吖頭↗ 提交于 2019-12-10 14:37:45
问题 I have an application and I want to test if I get correct messages from my logger. A short example (you may switch between log4r and logger): gem 'minitest' require 'minitest/autorun' require 'log4r' #~ require 'logger' class Testlog < MiniTest::Test def setup if defined? Log4r @log = Log4r::Logger.new('log') @log.outputters << Log4r::StdoutOutputter.new('stdout', :level => Log4r::INFO) else @log = Logger.new(STDOUT) @log.level = Logger::INFO end end def test_silent assert_silent{ @log.debug(