0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rubyでドローポーカーを作ってみる~test-unit準備編~

Last updated at Posted at 2020-07-22

概要

rubyでドローポーカーを作ってみる~準備編~

に続いて。

ソース: https://github.com/rytkmt/ruby_poker

test-unit全然知らない・・・ということで今回はtest-unitの準備をしていきます。

準備

こちらの公式ページを参考に進めていく

が、gemではないので少し手順が変わりそう・・・
なのでそれも含めて手順を記録として残していきます

初期ファイルの準備

$ cd ruby_poker
$ bundle gem -t minitest ./
git status -sb

A  .gitignore
A  .travis.yml
A  CODE_OF_CONDUCT.md
A  Gemfile
A  LICENSE.txt
A  Rakefile
A  bin/console
A  bin/setup
A  lib/ruby_poker.rb
A  lib/ruby_poker/version.rb
A  ruby_poker.gemspec
A  test/ruby_poker_test.rb
A  test/test_helper.rb

結構作られる

gemではないためgemspec削除

$ git rm ruby_poker.gemspec

ファイルの修正

Gemfile

Gemfile
-# Specify your gem's dependencies in ruby_poker.gemspec
-gemspec
+gem "rake"
+group :test do
+  gem "pry-byebug"
+  gem "test-unit"
+  gem "test-unit-rr"
+end

gemspecの行削除
代わりにminitestからtest-unitに変更なのでまずgemをインストール

$ bundle install

このとき、bundlerにてインストールされたファイルがgitに上がらないように.gitignoreを必要に応じて編集

Rakefile

Rakefile
-require "bundler/gem_tasks"
 require "rake/testtask"

test/test_helper.rb

test/test_helper.rb
 $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
 require "ruby_poker"
 
-require "minitest/autorun"
+require "pry"
+require "test/unit"
+require "test/unit/rr"

test/ruby_poker_test.rb

test/ruby_poker_test.rb
 require "test_helper"
 
-class RubyPokerTest < Minitest::Test
+class RubyPokerTest < Test::Unit::TestCase
   def test_that_it_has_a_version_number
     refute_nil ::RubyPoker::VERSION
   end

bin/console

bundle exec consoleを実行したときにruby_pokerはLOAD_PATHに居ないためエラーになる。そのためLOAD_PATHに追加する

bin/console
 require "bundler/setup"
+$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
+
 require "ruby_poker"

動作確認

console

bundle exec console を実行し、irbが立ち上がればOK

test

bundle exec rake testを実行し1件は失敗するようにテストケースがサンプルとして作られてるため、1件成功、1件失敗となればOK

$ rake test
/home/vagrant/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/file_utils.rb:54: warning: Insecure world writable dir /home in PATH, mode 040707
Loaded suite /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/rake_test_loader
Started
F
==============================================================================================================================================================
      6:   end
      7: 
      8:   def test_it_does_something_useful
  =>  9:     assert false
     10:   end
     11: end
/home/vagrant/private_workspace/ruby_poker/test/ruby_poker_test.rb:9:in `test_it_does_something_useful'
Failure: test_it_does_something_useful(RubyPokerTest): <false> is not true.
==============================================================================================================================================================
.
Finished in 0.004560792 seconds.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
2 tests, 2 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
50% passed
--------------------------------------------------------------------------------------------------------------------------------------------------------------
438.52 tests/s, 438.52 assertions/s
rake aborted!
Command failed with status (1)

Tasks: TOP => test
(See full trace by running task with --trace)

続き


rubyでドローポーカーを作ってみる~実装編1(カード)~

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?