Skip to content

Commit

Permalink
added characters translator
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezy committed Aug 19, 2012
1 parent 25ae6c9 commit 5a0bf49
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ChangeLog
Expand Up @@ -4,7 +4,7 @@
* Added name_suffix translator
* Added domain_name translator
* Added user_name translator

* Added characters translator

=== Version 0.8 / 2012-6-9
* Enhancements
Expand Down
1 change: 1 addition & 0 deletions features/data_magic.feature
Expand Up @@ -41,6 +41,7 @@ Feature: Functionality of the data_magic gem
And the value for "sentence" should exist
And the value for "sentences" should exist
And the value for "paragraphs" should exist
And the value for "characters" should be 255 characters long

Scenario: Boolean values
Then the value for "bool_true" should be true
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/data_magic_steps.rb
Expand Up @@ -33,6 +33,10 @@ class TestClass
@data[key].split(' ').size.should >= length.to_i
end

Then /^the value for "(.*?)" should be (\d+) characters long$/ do |key, length|
@data[key].length.should == length.to_i
end

Then /^the value for "(.+)" should exist$/ do |key|
@data[key].should_not be_nil
end
Expand Down
1 change: 1 addition & 0 deletions features/yaml/example.yml
Expand Up @@ -23,6 +23,7 @@ dm:
sentence: ~sentence
sentences: ~sentences
paragraphs: ~paragraphs
characters: ~characters
bool_true: true
bool_false: false

Expand Down
7 changes: 7 additions & 0 deletions lib/data_magic/translation.rb
Expand Up @@ -127,6 +127,13 @@ def paragraphs(paragraph_count = 3)
Faker::Lorem.paragraphs(paragraph_count).join('\n\n')
end

#
# return random characters - default is 255 characters
#
def characters(character_count = 255)
Faker::Lorem.characters(character_count)
end

#
# return a random email address
#
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/translation_spec.rb
Expand Up @@ -230,6 +230,12 @@ def set_field_value(value)
set_field_value '~paragraphs(10)'
example.data_for('key')['field'].split('\n\n').size.should == 10
end

it "should add characters" do
Faker::Lorem.should_receive(:characters).and_return('abcdefg')
set_field_value '~characters'
example.data_for('key').should have_field_value 'abcdefg'
end
end

context "translating boolean values" do
Expand Down

0 comments on commit 5a0bf49

Please sign in to comment.