projectでtranspecを使ってみた
gemをupdate
gem install rubygems-update
sudo gem update --system
transpecを実行
gem install transpec
convert結果
Summary:
1468 conversions
from: obj.should
to: expect(obj).to
201 conversions
from: obj.stub(:message)
to: allow(obj).to receive(:message)
81 conversions
from: obj.should_not
to: expect(obj).not_to
54 conversions
from: collection.should have(n).items
to: expect(collection.size).to eq(n)
51 conversions
from: obj.should_receive(:message)
to: expect(obj).to receive(:message)
49 conversions
from: == expected
to: eq(expected)
40 conversions
from: Klass.any_instance.stub(:message)
to: allow_any_instance_of(Klass).to receive(:message)
27 conversions
from: Klass.any_instance.should_receive(:message)
to: expect_any_instance_of(Klass).to receive(:message)
18 conversions
from: obj.should_not_receive(:message)
to: expect(obj).not_to receive(:message)
6 conversions
from: lambda { }.should
to: expect { }.to
5 conversions
from: Klass.any_instance.should_not_receive(:message)
to: expect_any_instance_of(Klass).not_to receive(:message)
5 conversions
from: it '...' do should have(n).items end
to: it '...' do expect(subject.size).to eq(n) end
3 conversions
from: lambda { }.should_not
to: expect { }.not_to
2 conversions
from: its([:key]) { }
to: describe '[:key]' do subject { super()[:key] }; it { } end
1 conversion
from: expect { }.not_to raise_error(SpecificErrorClass)
to: expect { }.not_to raise_error
2011 conversions, 0 incompletes, 59 warnings, 0 errors
そして、テストを回す
1892 examples, 7 failures, 223 pendings
7個くらい落ちました。
ArgumentError:
The expect syntax does not support operator matchers, so you must pass a matcher to `#to`.
この改行の仕方で変換されてたので落ちた
expect(a_request(:get, "http://fake.com")).to
have_been_made
これだと大丈夫
expect(a_request(:get, "http://fake.com")).
to have_been_made
OR
expect(a_request(:get, "http://fake.com")).to have_been_made
変換失敗してたのは、これくらいでした。
大体ちゃんと変換してくれてました。ありがとうございます。
rspecを2.99にする
Gemfileを編集
- gem 'rspec-rails', '~> 2.14.2'
+ gem 'rspec-rails', '~> 2.99.0'
bundle exec update rspec
そして、transpec
Summary:
83 conversions
from: it { should ... }
to: it { is_expected.to ... }
66 conversions
from: be_false
to: be_falsey
55 conversions
from: be_true
to: be_truthy
42 conversions
from: describe 'some model' { }
to: describe 'some model', :type => :model { }
21 conversions
from: describe 'some controller' { }
to: describe 'some controller', :type => :controller { }
19 conversions
from: describe 'some routing' { }
to: describe 'some routing', :type => :routing { }
16 conversions
from: it { should_not ... }
to: it { is_expected.not_to ... }
11 conversions
from: pending
to: skip
4 conversions
from: describe 'some request' { }
to: describe 'some request', :type => :request { }
3 conversions
from: describe 'some helper' { }
to: describe 'some helper', :type => :helper { }
1 conversion
from: before { example }
to: before { |example| example }
321 conversions, 0 incompletes, 0 warnings, 0 errors
A commit message that describes the conversion summary was generated to
.git/COMMIT_EDITMSG. To use the message, type the following command for
the next commit:
git commit -aeF .git/COMMIT_EDITMSG
Done! Now run rspec and check if everything is green.
warningが少しでる
`mock_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead.
ということでGemfileに追加
+ gem 'rspec-activemodel-mocks'
もうひとつ
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead.
warningの通りに直しました
rspec3にする
gem 'rspec-rails', '~> 3.0.1'
bundle update rspec
RAILS_ENV=test bundle exec rake parallel:create\[4\] db:migrate parallel:prepare\[4\]
RAILS_ENV=test bundle exec rake parallel:spec\[4\]
でテストまわす
パラレルでまわしてます
warning
WebMock::RequestPatternMatcher implements a legacy RSpec matcher
ということで、webmockのバージョンあげる
gem 'webmock', '~> 1.18.0'
Requiring rspec/autorun
when running RSpec via the rspec
command is deprecated.
なので、spec/spec_helper.rbの
require 'rspec/autrun'
を消す
rspec-rails使ってるので、rails generate rspec:installし直して、設定見直そうと
ちょっと、がんばったが、はまったので、とりあえずやめた