Skip to content

Commit ae7fa05

Browse files
committed
Refactor RSpec for AnnotateModels.resolve_filename
1 parent 89cd19e commit ae7fa05

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,50 +1861,59 @@ class Foo < ActiveRecord::Base
18611861
end
18621862
end
18631863

1864-
describe '#resolve_filename' do
1865-
it 'should return the test path for a model' do
1866-
filename_template = 'test/unit/%MODEL_NAME%_test.rb'
1867-
model_name = 'example_model'
1868-
table_name = 'example_models'
1869-
1870-
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
1871-
expect(filename). to eq 'test/unit/example_model_test.rb'
1864+
describe '.resolve_filename' do
1865+
subject do
1866+
AnnotateModels.resolve_filename(filename_template, model_name, table_name)
18721867
end
18731868

1874-
it 'should return the additional glob' do
1875-
filename_template = '/foo/bar/%MODEL_NAME%/testing.rb'
1876-
model_name = 'example_model'
1877-
table_name = 'example_models'
1869+
context 'When model_name is "example_model" and table_name is "example_models"' do
1870+
let(:model_name) { 'example_model' }
1871+
let(:table_name) { 'example_models' }
18781872

1879-
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
1880-
expect(filename). to eq '/foo/bar/example_model/testing.rb'
1881-
end
1873+
context "when filename_template is 'test/unit/%MODEL_NAME%_test.rb'" do
1874+
let(:filename_template) { 'test/unit/%MODEL_NAME%_test.rb' }
18821875

1883-
it 'should return the additional glob' do
1884-
filename_template = '/foo/bar/%PLURALIZED_MODEL_NAME%/testing.rb'
1885-
model_name = 'example_model'
1886-
table_name = 'example_models'
1876+
it 'returns the test path for a model' do
1877+
is_expected.to eq 'test/unit/example_model_test.rb'
1878+
end
1879+
end
18871880

1888-
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
1889-
expect(filename). to eq '/foo/bar/example_models/testing.rb'
1890-
end
1881+
context "when filename_template is '/foo/bar/%MODEL_NAME%/testing.rb'" do
1882+
let(:filename_template) { '/foo/bar/%MODEL_NAME%/testing.rb' }
1883+
1884+
it 'returns the additional glob' do
1885+
is_expected.to eq '/foo/bar/example_model/testing.rb'
1886+
end
1887+
end
18911888

1892-
it 'should return the fixture path for a model' do
1893-
filename_template = 'test/fixtures/%TABLE_NAME%.yml'
1894-
model_name = 'example_model'
1895-
table_name = 'example_models'
1889+
context "when filename_template is '/foo/bar/%PLURALIZED_MODEL_NAME%/testing.rb'" do
1890+
let(:filename_template) { '/foo/bar/%PLURALIZED_MODEL_NAME%/testing.rb' }
18961891

1897-
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
1898-
expect(filename). to eq 'test/fixtures/example_models.yml'
1892+
it 'returns the additional glob' do
1893+
is_expected.to eq '/foo/bar/example_models/testing.rb'
1894+
end
1895+
end
1896+
1897+
context "when filename_template is 'test/fixtures/%TABLE_NAME%.yml'" do
1898+
let(:filename_template) { 'test/fixtures/%TABLE_NAME%.yml' }
1899+
1900+
it 'returns the fixture path for a model' do
1901+
is_expected.to eq 'test/fixtures/example_models.yml'
1902+
end
1903+
end
18991904
end
19001905

1901-
it 'should return the fixture path for a nested model' do
1902-
filename_template = 'test/fixtures/%PLURALIZED_MODEL_NAME%.yml'
1903-
model_name = 'parent/child'
1904-
table_name = 'parent_children'
1906+
context 'When model_name is "parent/child" and table_name is "parent_children"' do
1907+
let(:model_name) { 'parent/child' }
1908+
let(:table_name) { 'parent_children' }
1909+
1910+
context "when filename_template is 'test/fixtures/%PLURALIZED_MODEL_NAME%.yml'" do
1911+
let(:filename_template) { 'test/fixtures/%PLURALIZED_MODEL_NAME%.yml' }
19051912

1906-
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
1907-
expect(filename). to eq 'test/fixtures/parent/children.yml'
1913+
it 'returns the fixture path for a nested model' do
1914+
is_expected.to eq 'test/fixtures/parent/children.yml'
1915+
end
1916+
end
19081917
end
19091918
end
19101919

0 commit comments

Comments
 (0)