mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-04 21:01:27 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
81 lines
1.8 KiB
Ruby
81 lines
1.8 KiB
Ruby
require 'rails_helper'
|
|
require 'cache'
|
|
|
|
describe Gaps do
|
|
|
|
|
|
it 'returns no gaps for empty data' do
|
|
expect(Gaps.new(nil, nil)).to be_blank
|
|
end
|
|
|
|
it 'returns no gaps with one element' do
|
|
expect(Gaps.new([1], [1])).to be_blank
|
|
end
|
|
|
|
it 'returns no gaps when all elements are present' do
|
|
expect(Gaps.new([1,2,3], [1,2,3])).to be_blank
|
|
end
|
|
|
|
context "single element gap" do
|
|
let(:gap) { Gaps.new([1,3], [1,2,3]) }
|
|
|
|
it 'has a gap for post 3' do
|
|
expect(gap).not_to be_blank
|
|
expect(gap.before[3]).to eq([2])
|
|
expect(gap.after).to be_blank
|
|
end
|
|
end
|
|
|
|
context "larger gap" do
|
|
let(:gap) { Gaps.new([1,2,3,6,7], [1,2,3,4,5,6,7]) }
|
|
|
|
it 'has a gap for post 6' do
|
|
expect(gap).not_to be_blank
|
|
expect(gap.before[6]).to eq([4,5])
|
|
expect(gap.after).to be_blank
|
|
end
|
|
end
|
|
|
|
context "multiple gaps" do
|
|
let(:gap) { Gaps.new([1,5,6,7,10], [1,2,3,4,5,6,7,8,9,10]) }
|
|
|
|
it 'has both gaps' do
|
|
expect(gap).not_to be_blank
|
|
expect(gap.before[5]).to eq([2,3,4])
|
|
expect(gap.before[10]).to eq([8,9])
|
|
expect(gap.after).to be_blank
|
|
end
|
|
end
|
|
|
|
context "a gap in the beginning" do
|
|
let(:gap) { Gaps.new([2,3,4], [1,2,3,4]) }
|
|
|
|
it 'has the gap' do
|
|
expect(gap).not_to be_blank
|
|
expect(gap.before[2]).to eq([1])
|
|
expect(gap.after).to be_blank
|
|
end
|
|
end
|
|
|
|
context "a gap in the ending" do
|
|
let(:gap) { Gaps.new([1,2,3], [1,2,3,4]) }
|
|
|
|
it 'has the gap' do
|
|
expect(gap).not_to be_blank
|
|
expect(gap.before).to be_blank
|
|
expect(gap.after[3]).to eq([4])
|
|
end
|
|
end
|
|
|
|
context "a large gap in the ending" do
|
|
let(:gap) { Gaps.new([1,2,3], [1,2,3,4,5,6]) }
|
|
|
|
it 'has the gap' do
|
|
expect(gap).not_to be_blank
|
|
expect(gap.before).to be_blank
|
|
expect(gap.after[3]).to eq([4,5,6])
|
|
end
|
|
end
|
|
|
|
|
|
end
|