Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Ruby lets you override methods on existing objects, so you don't need to derive a new one to override it.

If you change the constructor to take the dependency explicitly as a parameter you don't need your initialize method. see Dependency Injection Dependency Injection. Note: If you follow this pattern everywhere you end up with classes either being building blocks or for wiring blocks together. Factories etc. Some people don't like this... so the other option is...

RSpec lets you mock methods on any instance of a specific class... see https://www.relishapp.com/rspec/rspec-mocks/v/2-6/docs/method-stubs/stub-on-any-instance-of-a-class

describe "any_instance.stub" do
 it "returns the specified value on any instance of the class" do
 Object.any_instance.stub(:foo).and_return(:return_value)
 o = Object.new
 o.foo.should eq(:return_value)
 end
end

Ruby lets you override methods on existing objects, so you don't need to derive a new one to override it.

If you change the constructor to take the dependency explicitly as a parameter you don't need your initialize method. see Dependency Injection. Note: If you follow this pattern everywhere you end up with classes either being building blocks or for wiring blocks together. Factories etc. Some people don't like this... so the other option is...

RSpec lets you mock methods on any instance of a specific class... see https://www.relishapp.com/rspec/rspec-mocks/v/2-6/docs/method-stubs/stub-on-any-instance-of-a-class

describe "any_instance.stub" do
 it "returns the specified value on any instance of the class" do
 Object.any_instance.stub(:foo).and_return(:return_value)
 o = Object.new
 o.foo.should eq(:return_value)
 end
end

Ruby lets you override methods on existing objects, so you don't need to derive a new one to override it.

If you change the constructor to take the dependency explicitly as a parameter you don't need your initialize method. see Dependency Injection. Note: If you follow this pattern everywhere you end up with classes either being building blocks or for wiring blocks together. Factories etc. Some people don't like this... so the other option is...

RSpec lets you mock methods on any instance of a specific class... see https://www.relishapp.com/rspec/rspec-mocks/v/2-6/docs/method-stubs/stub-on-any-instance-of-a-class

describe "any_instance.stub" do
 it "returns the specified value on any instance of the class" do
 Object.any_instance.stub(:foo).and_return(:return_value)
 o = Object.new
 o.foo.should eq(:return_value)
 end
end
Source Link

Ruby lets you override methods on existing objects, so you don't need to derive a new one to override it.

If you change the constructor to take the dependency explicitly as a parameter you don't need your initialize method. see Dependency Injection. Note: If you follow this pattern everywhere you end up with classes either being building blocks or for wiring blocks together. Factories etc. Some people don't like this... so the other option is...

RSpec lets you mock methods on any instance of a specific class... see https://www.relishapp.com/rspec/rspec-mocks/v/2-6/docs/method-stubs/stub-on-any-instance-of-a-class

describe "any_instance.stub" do
 it "returns the specified value on any instance of the class" do
 Object.any_instance.stub(:foo).and_return(:return_value)
 o = Object.new
 o.foo.should eq(:return_value)
 end
end
lang-rb

AltStyle によって変換されたページ (->オリジナル) /