-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared specs for the interface of Random::Formatter
* Depend on the instance method `bytes` * Ensure the output is the same if the input bytes are the same * Ensure the output is not the same if the input bytes are not the same Right now, this is only used in the specs for `alphanumeric`, since this is the only method of Random::Formatter with specs, but this should be used in every other spec we add to this folder, since the specs have no dependency on the exact format that is being used.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require_relative '../../../../spec_helper' | ||
|
||
describe :random_formatter_interface, shared: true do | ||
it "calls the method #bytes for 4 blocks of 4 bytes" do | ||
bytes = mock('bytes') | ||
bytes.extend(Random::Formatter) | ||
bytes.should_receive(:bytes).with(4).exactly(4).and_return("\x00".b * 4) | ||
bytes.send(@method) | ||
end | ||
|
||
it "has the same output if the random byte streams are the same" do | ||
bytes = Object.new | ||
bytes.extend(Random::Formatter) | ||
def bytes.bytes(n) | ||
"\x00".b * n | ||
end | ||
bytes.send(@method).should == bytes.send(@method) | ||
end | ||
|
||
it "has different output if the random byte streams are not the same" do | ||
lhs = Object.new | ||
lhs.extend(Random::Formatter) | ||
def lhs.bytes(n) | ||
"\x00".b * n | ||
end | ||
rhs = Object.new | ||
rhs.extend(Random::Formatter) | ||
def rhs.bytes(n) | ||
"\x01".b * n | ||
end | ||
lhs.send(@method).should != rhs.send(@method) | ||
end | ||
end |