Skip to content

Commit

Permalink
dry specs with shared examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbeales committed Mar 27, 2018
1 parent 3954d8c commit 2732f69
Show file tree
Hide file tree
Showing 28 changed files with 117 additions and 159 deletions.
12 changes: 5 additions & 7 deletions spec/models/arm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

describe '#respond_to?' do
include_context 'shared attributes'
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end

context '#number' do
it { expect(subject.respond_to?(:number)).to be_truthy }
end
Expand All @@ -31,9 +29,9 @@
context '#study_events' do
it { expect(subject.respond_to?(:study_events)).to be_truthy }
end
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down Expand Up @@ -69,7 +67,7 @@

it do
subject.schedule.arms.concat(subject)
expect(subject.schedule.arms.size).to be > 0
expect(subject.schedule.arms.size).to be.positive?
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/models/assessment_instrument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
context '#instrument' do
it { expect(attribute?(:instrument)).to be_truthy }
end
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#instrument' do
Expand Down Expand Up @@ -109,7 +108,6 @@
include_context 'destroy subject'

it { expect(Instrument.exists?(instrument.id)).to be_truthy }

it { expect(Assessment.exists?(assess.id)).to be_truthy }
end

Expand Down
7 changes: 3 additions & 4 deletions spec/models/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@
context '#scores' do
it { expect(subject.respond_to?(:scores)).to be_truthy }
end
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#visit' do
Expand Down Expand Up @@ -97,7 +96,7 @@
end

context 'with default order_number' do
it { expect(subject.order_number).to be > 0 }
it { expect(subject.order_number).to be.positive? }
end
end

Expand Down
13 changes: 4 additions & 9 deletions spec/models/choice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@
end

describe '#respond_to?' do
include_context 'shared attributes'

it { expect(subject.respond_to?(:value)).to be_truthy }
it { expect(subject.respond_to?(:description)).to be_truthy }
it { expect(subject.respond_to?(:score)).to be_truthy }
it { expect(subject.respond_to?(:response_scale)).to be_truthy }
it { expect(subject.respond_to?(:responses)).to be_truthy }
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end

include_examples 'common attributes'
end

describe '#response_scale' do
Expand Down
9 changes: 3 additions & 6 deletions spec/models/folder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(attribute?(:name)).to be_truthy }
end
context '#projects' do
it { expect(attribute?(:projects)).to be_truthy }
end
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down
7 changes: 4 additions & 3 deletions spec/models/hipaa_identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
end

describe '#respond_to?' do
it { expect(subject.respond_to?(:name)).to be_truthy }

it { expect(subject.respond_to?(:random_name)).not_to be_truthy }
include_context 'shared attributes'

include_examples 'name'
it { expect(subject.respond_to?(:not_attribute)).not_to be_truthy }
end

describe '#name' do
Expand Down
9 changes: 3 additions & 6 deletions spec/models/instrument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:content)).to be_truthy }
it { expect(subject.respond_to?(:title)).to be_truthy }
it { expect(subject.respond_to?(:instructions)).to be_truthy }
Expand All @@ -26,9 +23,9 @@
it { expect(subject.respond_to?(:study_event_instruments)).to be_truthy }
it { expect(subject.respond_to?(:study_events)).to be_truthy }
it { expect(subject.respond_to?(:items)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down
15 changes: 6 additions & 9 deletions spec/models/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:choices)).to be_truthy }
it { expect(subject.respond_to?(:instrument)).to be_truthy }
it { expect(subject.respond_to?(:response_scale)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
it { expect(attribute?(:choices)).to be_truthy }
it { expect(attribute?(:instrument)).to be_truthy }
it { expect(attribute?(:response_scale)).to be_truthy }

include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down
5 changes: 2 additions & 3 deletions spec/models/journal_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
it { expect(subject.respond_to?(:entry_date)).to be_truthy }
it { expect(subject.respond_to?(:entry)).to be_truthy }
it { expect(subject.respond_to?(:journal)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#entry_date' do
Expand Down
17 changes: 7 additions & 10 deletions spec/models/journal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:participant)).to be_truthy }
it { expect(subject.respond_to?(:journal_entries)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
it { expect(attribute?(:participant)).to be_truthy }
it { expect(attribute?(:journal_entries)).to be_truthy }

include_examples 'name'
include_examples 'common attributes'
end

describe '#list_entries' do
Expand All @@ -36,7 +33,7 @@

describe '#read_entry' do
it do
expect(subject.read_entry(Date.today).size).to be > 0
expect(subject.read_entry(Date.today).size).to be.positive?
end
end

Expand Down Expand Up @@ -103,7 +100,7 @@
end

describe '#create_entry_for_today' do
it { expect(subject.journal_entries.size).to be > 0 }
it { expect(subject.journal_entries.size).to be.positive? }
end

describe '#created_at today' do
Expand Down
5 changes: 2 additions & 3 deletions spec/models/participant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
it { expect(subject.respond_to?(:journal)).to be_truthy }
it { expect(subject.respond_to?(:survey_participants)).to be_truthy }
it { expect(subject.respond_to?(:surveys)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#email' do
Expand Down
9 changes: 3 additions & 6 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:title)).to be_truthy }
it { expect(subject.respond_to?(:folder)).to be_truthy }
it { expect(subject.respond_to?(:status)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down
9 changes: 3 additions & 6 deletions spec/models/response_scale_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@
describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:items)).to be_truthy }
it { expect(subject.respond_to?(:choices)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#destroy!' do
Expand Down
5 changes: 2 additions & 3 deletions spec/models/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
it { expect(subject.respond_to?(:value)).to be_truthy }
it { expect(subject.respond_to?(:assessment)).to be_truthy }
it { expect(subject.respond_to?(:choice)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#assessment' do
Expand Down
10 changes: 3 additions & 7 deletions spec/models/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@

describe '#respond_to?' do
include_context 'shared attributes'

context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end

it { expect(subject.respond_to?(:study)).to be_truthy }
it { expect(subject.respond_to?(:arms)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#name' do
Expand Down
9 changes: 4 additions & 5 deletions spec/models/score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

describe '#respond_to?' do
include_context 'shared attributes'

it { expect(subject.respond_to?(:name)).to be_truthy }

it { expect(subject.respond_to?(:assessment)).to be_truthy }
it { expect(subject.respond_to?(:score)).to be_truthy }
it { expect(subject.respond_to?(:visit)).to be_truthy }
it { expect(subject.respond_to?(:survey)).to be_truthy }
it { expect(subject.respond_to?(:participant)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#score' do
Expand Down
5 changes: 2 additions & 3 deletions spec/models/study_event_instrument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

it { expect(subject.respond_to?(:study_event)).to be_truthy }
it { expect(subject.respond_to?(:instrument)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#instrument' do
Expand Down
9 changes: 3 additions & 6 deletions spec/models/study_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
include_context 'shared attributes'

it { expect(subject.respond_to?(:arm)).to be_truthy }
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:schedule)).to be_truthy }
it { expect(subject.respond_to?(:study)).to be_truthy }
it { expect(subject.respond_to?(:study_event_instruments)).to be_truthy }
it { expect(subject.respond_to?(:instruments)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down
6 changes: 2 additions & 4 deletions spec/models/study_participant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

it { expect(subject.respond_to?(:study)).to be_truthy }
it { expect(subject.respond_to?(:participant)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end

include_examples 'common attributes'
end

describe '#study' do
Expand Down Expand Up @@ -91,7 +90,6 @@
include_context 'destroy subject'

it { expect(Participant.exists?(participant.id)).to be_truthy }

it { expect(Study.exists?(study.id)).to be_truthy }
end

Expand Down
9 changes: 3 additions & 6 deletions spec/models/study_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@

describe '#respond_to?' do
include_context 'shared attributes'
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end

it { expect(subject.respond_to?(:schedule)).to be_truthy }
it { expect(subject.respond_to?(:study_participants)).to be_truthy }
it { expect(subject.respond_to?(:participants)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
include_examples 'name'
include_examples 'common attributes'
end

describe '#name' do
Expand Down
Loading

0 comments on commit 2732f69

Please sign in to comment.