Last active
November 17, 2015 07:56
-
-
Save YumaInaura/fde74a72d7fa3c670a71 to your computer and use it in GitHub Desktop.
RSpec - change の基本動作。 ( by / from / to の使い方 ) ref: http://qiita.com/Yinaura/items/62dc0d87f968f43e335b
This file contains hidden or 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
x = 1 | |
expect { x += 1 }.to change { x } | |
# => true |
This file contains hidden or 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
x = 1 | |
expect { x += 2 }.to change { x } | |
# => true |
This file contains hidden or 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
x = 1 | |
expect { x += 1; x -= 1; }.to change { x } | |
# => RSpec::Expectations::ExpectationNotMetError: result should have changed, but is still 1 |
This file contains hidden or 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
x = 1 | |
expect { x += 5 }.to change { x }.by(5) | |
# => true |
This file contains hidden or 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
x = 1 | |
expect { x -= 5 }.to change { x }.by(-5) | |
# => true |
This file contains hidden or 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
x = 3 | |
expect { x += 4 }.to change { x }.by(7) | |
# => RSpec::Expectations::ExpectationNotMetError: result should have been changed by 7, but was changed by 4 |
This file contains hidden or 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
x = 3 | |
expect { x += 4 }.to change { x }.by(4) | |
# => true |
This file contains hidden or 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
x = 3 | |
expect { x += 4 }.to change { x }.from(3).to(7) | |
# => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment