Last active
June 24, 2016 22:24
-
-
Save andrelip/a13d5b2db01f4d0d80ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
include Pipeline | |
RSpec.describe Pipeline, :type => :model do | |
context "#pipe" do | |
context "receiving scope, an initial value and a block" do | |
it "should work have his own inspect defined" do | |
result = pipe self, 1 do | |
inspect | |
end | |
result.should == "1" | |
end | |
it "should chain methods passing a result value from a method as the | |
first argument of the next one" do | |
def sum(a, b) | |
a + b | |
end | |
result = pipe self, 1 do | |
sum(2) | |
end | |
result.should == 3 | |
end | |
it "should chain any methods" do | |
def concatenate(a, b) | |
a + b | |
end | |
result = pipe self, "Hey" do | |
concatenate(" you!") | |
concatenate(" Can you hear me?") | |
end | |
result.should == ("Hey you! Can you hear me?") | |
end | |
it "should work with external modules encapsuled" do | |
def sin(number) | |
Math.sin(number) | |
end | |
result = pipe self, 0.0 do | |
sin | |
end | |
result.should == (0.0) | |
end | |
it "should work with external encapsuled on lambda" do | |
result = pipe self, 0.0 do | |
external -> (entry_value, &b) {Math.cos entry_value} | |
end | |
result.should == (1.0) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment