Class: JobSpec::AdhocExpectations
- Inherits:
-
Object
- Object
- JobSpec::AdhocExpectations
- Defined in:
- lib/job_spec/adhoc_expectations.rb
Class Method Summary collapse
Instance Method Summary collapse
- #description(description) ⇒ Object
-
#initialize(expectation, &block) ⇒ AdhocExpectations
constructor
A new instance of AdhocExpectations.
- #roles(*roles) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(expectation, &block) ⇒ AdhocExpectations
Returns a new instance of AdhocExpectations.
30 31 32 33 34 |
# File 'lib/job_spec/adhoc_expectations.rb', line 30 def initialize(expectation, &block) @expectation = expectation @block = block instance_eval(&block) unless block.nil? end |
Class Method Details
.clear! ⇒ Object
3 4 5 |
# File 'lib/job_spec/adhoc_expectations.rb', line 3 def self.clear! @expectations = nil end |
.define(expectation, &block) ⇒ Object
7 8 9 10 |
# File 'lib/job_spec/adhoc_expectations.rb', line 7 def self.define(expectation, &block) @expectations ||= [] @expectations << new(expectation, &block) end |
.roles ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/job_spec/adhoc_expectations.rb', line 12 def self.roles roles = {} @expectations.each do |expectation| expectation.to_a.each do |role_expectation| roles[role_expectation[:role]] ||= { name: role_expectation[:role], expectations: [] } roles[role_expectation[:role]][:expectations] << { expectation: role_expectation[:expectation], description: role_expectation[:description] } end end roles.values end |
Instance Method Details
#description(description) ⇒ Object
36 37 38 |
# File 'lib/job_spec/adhoc_expectations.rb', line 36 def description(description) @description = description end |
#roles(*roles) ⇒ Object
40 41 42 |
# File 'lib/job_spec/adhoc_expectations.rb', line 40 def roles(*roles) @roles = roles end |
#to_a ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/job_spec/adhoc_expectations.rb', line 44 def to_a @roles.map do |role| { role: role, expectation: @expectation, description: @description } end end |