1
2

More than 3 years have passed since last update.

WSL上で実行したRSpecにエラー(NotImplementedError:fork() function is unimplemented on this machine)が出る問題の解決法

Last updated at Posted at 2020-07-25

ポートフォリオ作成のために勉強目的で作成していたプログラムでRSpecがエラーで動作しなかったので解決方法を記載します。

結論から先に書くとWSL1にはUbuntu 18.04をインストールしましょうということです。

環境

  • ホストOS:Windows 10 64bit
  • 仮想環境:WSL1
  • ゲストOS:Ubuntu 20.04 LTS
  • Ruby:Ruby2.6.6
  • Rails:Rails5.2.4.3

使用しているGem

  • better_errors
  • byebug
  • capybara
  • factory_bot_rails
  • pry-byebug
  • rspec-rails
  • spring-commands-rspec
  • sqlite3
  • webdrivers

全部だと多いのでテストグループに記載しているgemのみです

エラー内容と解決方法

まずはWSL1上で開発していたプログラムをRSpecを使ってテストを開始しました。

しかしNotImplementedError:fork() function is unimplemented on this machineというエラーが出て動作しません。

Got 0 failures and 2 other errors:
     1.1) Failure/Error: visit '/'
          NotImplementedError:
            fork() function is unimplemented on this machine

          # ./spec/system/users_spec.rb:10:in `block (4 levels) in <top (required)>'

     1.2) Failure/Error:
                    @pid = Kernel.fork {
                      # Children of the forked process will inherit its process group
                      # This is to make sure that all grandchildren dies when this Process instance is killed
                      ::Process.setpgid 0, 0 if leader?
                      if @cwd
                        Dir.chdir(@cwd)
                      end
                      exec_r.close
          NotImplementedError:
            fork() function is unimplemented on this machine

エラーが出たものと同じソースコードを他のPC(Ubuntu 20.04)上で実行するとエラーもなく通ります。

ここで同じバージョンのOSで動くのでWSLが原因ではと考えます。

次にエラー名で検索するとGitHubのWSLリポジトリのIssueに同じエラーが出るというものがありました。
https://github.com/microsoft/WSL/issues/5238

RSpecでエラーが出た訳では無いですがWSL上でUbuntu 20.04を起動してエラーが出た点というのは一致しています。

なのでWSL1上でUbuntu 20.04を起動しているのが原因ではと考えます。
*ちなみにIssueにはWSL2を利用した場合は動作したと記載があるのでWSL2が利用できる場合は利用したほうが簡単に済むと思います。

調べてみるとQiitaにWSL1にはUbuntu 20.04をインストールしないほうが良いという記事がありました。
https://qiita.com/AumyF/items/eaf42dd3345a2285ff9e

RSpecでエラーが出るとは書いていないのでこれが原因かはわかりませんがとりあえずUbuntu 18.04をインストールしRSpecを実行してみるとエラーが無く通りました。

やっぱり最新版を使用するより安定している少し古いバージョンの方が開発には向いているかもと思いました。
これを教訓に最新版を使用する際は気をつけます。

最後にQiita初投稿&初心者なのでどこか問題点があれば教えていただきたいです。

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