Class: RSpec::Contracts::FulfillmentView

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/contracts/fulfillment_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(fulfillment) ⇒ FulfillmentView

Returns a new instance of FulfillmentView.



4
5
6
# File 'lib/rspec/contracts/fulfillment_view.rb', line 4

def initialize(fulfillment)
  @fulfillment = fulfillment
end

Instance Method Details

#contracts_countObject



28
29
30
# File 'lib/rspec/contracts/fulfillment_view.rb', line 28

def contracts_count
  pluralize @fulfillment.requirements_count, "contract"
end

#pluralize(number, noun) ⇒ Object



32
33
34
35
# File 'lib/rspec/contracts/fulfillment_view.rb', line 32

def pluralize(number, noun)
  suffix = (number == 1) ? "" : "s"
  "#{number} #{noun}#{suffix}"
end

#renderObject



8
9
10
# File 'lib/rspec/contracts/fulfillment_view.rb', line 8

def render
  @fulfillment.complete? ? render_complete : render_incomplete
end

#render_completeObject



12
13
14
# File 'lib/rspec/contracts/fulfillment_view.rb', line 12

def render_complete
  "#{contracts_count} verified."
end

#render_incompleteObject



16
17
18
19
20
# File 'lib/rspec/contracts/fulfillment_view.rb', line 16

def render_incomplete
  lines = unfulfilled_views
  lines.unshift("WARNING: #{unfulfilled_views.count} of #{contracts_count} unverified.")
  lines.join "\n"
end

#unfulfilled_viewsObject



22
23
24
25
26
# File 'lib/rspec/contracts/fulfillment_view.rb', line 22

def unfulfilled_views
  @fulfillment.unfulfilled_requirements.map do |requirement|
    RSpec::Contracts::RequirementView.new(requirement).render
  end
end