[Ruby] Making draw poker with ruby ~test-unit preparation~

2 minute read

Overview

Try making draw poker with ruby ~Preparation~

Followed by.

Source: https://github.com/rytkmt/ruby_poker

test-unit I don’t know at all, so I will prepare test-unit this time.

Preparation

Please proceed with reference to this official page

However, since it is not a gem, the procedure may change a little… So I will record the procedure including that.

Initial file preparation

$ 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

Well made

gemspec deleted because it is not a gem

$ git rm ruby_poker.gemspec

File modification

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

Delete gemspec line Instead, change from minitest to test-unit, so install gem first

$ bundle install

At this time, edit .gitignore as necessary so that the files installed by bundler do not go up to git

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

When running bundle exec console, an error occurs because ruby_poker is not in LOAD_PATH. So add it to LOAD_PATH

bin/console


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

operation check

console

Run bundle exec console and irb will boot

test

Since a test case is made as a sample so that bundle exec rake test is executed and one fails, it is OK if one succeeds and one fails

$ 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)

continued

Try to make a draw poker with ruby ~ Implementation 1 (card) ~

Tags:

Updated: