Skip to content

Commit

Permalink
add attribute? shared_example
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbeales committed Mar 27, 2018
1 parent 2732f69 commit 5996886
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 32 deletions.
2 changes: 1 addition & 1 deletion spec/models/arm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

it do
subject.schedule.arms.concat(subject)
expect(subject.schedule.arms.size).to be.positive?
expect(subject.schedule.arms.size).to be > 0
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
end

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

Expand Down
4 changes: 2 additions & 2 deletions spec/models/journal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

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

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

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

describe '#created_at today' do
Expand Down
11 changes: 5 additions & 6 deletions spec/models/score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
describe '#respond_to?' do
include_context 'shared attributes'

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 }

include_examples 'attribute?', :survey
include_examples 'attribute?', :participant
include_examples 'attribute?', :visit
include_examples 'attribute?', :score
include_examples 'attribute?', :assessment
include_examples 'name'
include_examples 'common attributes'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/study_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

it { expect(subject.respond_to?(:arm)).to be_truthy }
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 }

include_examples 'attribute?', :study
include_examples 'name'
include_examples 'common attributes'
end
Expand Down
5 changes: 2 additions & 3 deletions spec/models/study_participant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
describe '#respond_to?' do
include_context 'shared attributes'

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

include_examples 'attribute?', :study
include_examples 'attribute?', :participant
include_examples 'common attributes'
end

Expand Down
4 changes: 2 additions & 2 deletions spec/models/survey_participant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
describe '#respond_to?' do
include_context 'shared attributes'

it { expect(subject.respond_to?(:survey)).to be_truthy }
it { expect(subject.respond_to?(:participant)).to be_truthy }
include_examples 'attribute?', :survey
include_examples 'attribute?', :participant
include_examples 'common attributes'
end

Expand Down
42 changes: 26 additions & 16 deletions spec/rspec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ JournalEntry
unique entry date
 {:timecop=>:freeze}
#to_s
 should eq "2018-03-27 19:10:38 UTC "
 should eq "2018-03-27 19:35:48 UTC "
#created_at today
 is created less than 5 minutes ago

Expand All @@ -350,7 +350,7 @@ Journal
 should be truthy
#list_entries
defaults to last 4
 should eq "2018-03-27 19:10:38 UTC 2012-12-12 00:00:00 UTC "
 should eq "2018-03-27 19:35:48 UTC 2012-12-12 00:00:00 UTC "
#read_entry
 should be > 0
#name
Expand Down Expand Up @@ -526,11 +526,16 @@ Score
 is an instance of Score
 is valid with valid attributes
#respond_to?
 should be truthy
 should be truthy
 should be truthy
 should be truthy
 should be truthy
#survey
 should be truthy
#participant
 should be truthy
#visit
 should be truthy
#score
 should be truthy
#assessment
 should be truthy
#name
 should be truthy
common attributes
Expand All @@ -551,8 +556,8 @@ Score
assessment and name
 should not raise Exception
duplicate assessment and name
 example at ./spec/models/score_spec.rb:79
 example at ./spec/models/score_spec.rb:85
 example at ./spec/models/score_spec.rb:78
 example at ./spec/models/score_spec.rb:84
#to_s
 prints assessment name: score
#destroy!
Expand Down Expand Up @@ -603,7 +608,8 @@ StudyEvent
 should be truthy
 should be truthy
 should be truthy
 should be truthy
#study
 should be truthy
#name
 should be truthy
common attributes
Expand All @@ -628,8 +634,10 @@ StudyParticipant
 is an instance of StudyParticipant
 is valid with valid attributes
#respond_to?
 should be truthy
 should be truthy
#study
 should be truthy
#participant
 should be truthy
common attributes
 should be truthy
#study
Expand Down Expand Up @@ -688,8 +696,10 @@ SurveyParticipant
 is an instance of SurveyParticipant
 is valid with valid attributes
#respond_to?
 should be truthy
 should be truthy
#survey
 should be truthy
#participant
 should be truthy
common attributes
 should be truthy
#survey
Expand Down Expand Up @@ -849,7 +859,7 @@ AlexaService
 should eq " Cannot find instrument blah. Please try again.\n"
 should eq "Below is a list of the ways you might have felt or behaved. Please check the boxes to tell me how often you have felt this way in the past week or so."
#read_all
 should eq "2018-03-27 19:10:36 UTC "
 should eq "2018-03-27 19:35:47 UTC "
 should not be nil

InstrumentLoaderCsv
Expand Down Expand Up @@ -877,6 +887,6 @@ InstrumentLoader
missing instrument
 should raise RuntimeError

Finished in 8.01 seconds (files took 4.39 seconds to load)
Finished in 9.13 seconds (files took 4.47 seconds to load)
462 examples, 0 failures

6 changes: 6 additions & 0 deletions spec/shared_example_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
it { expect(attribute?(:name)).to be_truthy }
end
end

RSpec.shared_examples 'attribute?' do |attribute|
context "##{attribute}" do
it { expect(attribute?(attribute)).to be_truthy }
end
end

0 comments on commit 5996886

Please sign in to comment.