LoginSignup
1
0

More than 1 year has passed since last update.

Aruba gemでfizz buzzテストを書いてみた

Last updated at Posted at 2021-10-26

Aruba gemでRSpec fizz buzzテストを書いてみた

参考資料

Aruba gemでCLIテストを支援する

この参考資料は初めてテストを書くような人でも理解しやすいものです.
この資料通りに進めるとほとんどエラーなく通るのですが,一つ苦戦したエラーの克服手順を紹介します.

エラー

参考資料通りに進めていき,実行してみると...

$bundle exec rspec spec/cli_spec.rb  

An error occurred while loading spec_helper. - Did you mean?
                    rspec ./spec/spec_helper.rb

Failure/Error: require 'aruba/rspec'

LoadError:
  cannot load such file -- aruba/rspec
# ./spec/support/aruba.rb:1:in `require'
# ./spec/support/aruba.rb:1:in `<top (required)>'
# ./spec/spec_helper.rb:18:in `require_relative'
# ./spec/spec_helper.rb:18:in `block in <top (required)>'
# ./spec/spec_helper.rb:18:in `each'
# ./spec/spec_helper.rb:18:in `<top (required)>'
No examples found.
No examples found.


Finished in 0.00001 seconds (files took 0.06403 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

Finished in 0.00001 seconds (files took 0.06403 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

このようなエラーが出てしまう.

そこで,

$ bundle install

で確認してみると,

Using rake 13.0.6
Using bundler 2.2.23
Using thor 1.1.0
Using fizzbuzz 0.1.0 from source at `.` and installing its executables
Bundle complete! 2 Gemfile dependencies, 4 gems now installed.
Bundled gems are installed into `./vendor/bundle`

入れたはずのArubaがなくなっている!!

解決法

aruba-rspecのセットアップのところで下記を実行.

$ bundle exec aruba init --test-framework rspec

実行後自動的にGemfileが下記のように書き加えられる.

Gemfile
source 'https://rubygems.org'

gemspec
gem 'aruba', '~> 0.14.2'

これを次のように書き換える.

Gemfile
source 'https://rubygems.org/'

# Specify your gem's dependencies in fizzbuzz.gemspec
gemspec

あとは参考資料通りすると,

 $ bundle exec rspec spec/cli_spec.rb                                       21.36h  火 10/26 12:21:07 2021

fizzbuzz command
  version option
    is expected to be successfully executed
    is expected to have output: "0.1.0"
  help option
    is expected to be successfully executed
    is expected to have output: "Commands:\n  fizzbuzz fizzbuzz        # Get fizzbuzz result from limit number\n  fizzbuzz help [COMM...e.\n      [--version], [--no-version]  # version\n  -d, [--debug], [--no-debug]      # debug mode\n"
  fizzbuzz subcommand
    is expected to be successfully executed
    is expected to have output: "FizzBuzz,1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz,11,Fizz,13,14,FizzBuzz"
  fizzbuzz subcommand invalid args
    is expected not to be successfully executed

Finished in 1.54 seconds (files took 0.13908 seconds to load)
7 examples, 0 failures

テストが無事通る.

1
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
1
0