Skip to content

Commit

Permalink
Specify desired state in unit spec
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0d1r2 committed Oct 1, 2024
1 parent e8f81e3 commit 276d20f
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ def country
end
end
end

context 'qualified with #with_private' do
it 'states that it should delegate method to the right object with right argument and makes is private' do
matcher = delegate_method(:method_name).to(:delegate).with_private
message = 'delegate #method_name to the #delegate object privately'

expect(matcher.description).to eq message
end
end
end

context 'when the subject is a class' do
Expand Down Expand Up @@ -655,4 +664,46 @@ def hello
end
end
end

context 'qualified with #with_private' do
context 'when using delegate from Rails' do
context 'when delegations were defined with :private' do
it 'accepts' do
define_class('Person') do
delegate :hello, to: :country, private: true
def country
end
end

person = Person.new

expect(person).to delegate_method(:hello).to(:country).with_private
end
end

context 'when delegations were not defined with :private' do
it 'rejects with the correct failure message' do
define_class('Person') do
delegate :hello, to: :country
def country
end
end

person = Person.new

message = <<-MESSAGE
Expected Person to delegate #hello to the #country object privately.
Person#hello did delegate to #country, but 'private: true' is missing.
MESSAGE

expectation = lambda do
expect(person).to delegate_method(:hello).to(:country).with_private
end

expect(&expectation).to fail_with_message(message)
end
end
end
end
end

0 comments on commit 276d20f

Please sign in to comment.