fake_friends 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module FakeFriends
2
- VERSION = "1.0.1"
2
+ VERSION = '1.0.3'
3
3
  end
data/lib/fake_friends.rb CHANGED
@@ -9,10 +9,18 @@ module FakeFriends
9
9
  class FakeFriend
10
10
  attr_reader :username, :name, :location, :description, :url, :posts
11
11
 
12
+ # Public: FakeFriend.all
13
+ #
14
+ # Returns a class instance Hash variable holding the
15
+ # user list defined in users.yml
16
+ def self.all
17
+ @friends_list
18
+ end
19
+
12
20
  # Public: FakeFriend.gather(n)
13
21
  # Returns n FakeFriend objects
14
22
  #
15
- # n - An Integer from 1 to 101.
23
+ # n - An Integer from 1 to 100.
16
24
  #
17
25
  # Examples
18
26
  #
@@ -21,8 +29,8 @@ module FakeFriends
21
29
  #
22
30
  # Returns an array of n FakeFriend objects
23
31
  def self.gather(n)
24
- raise ArgumentError, "Can only gather 1 to 101 FakeFriends" unless n.between?(1, 101)
25
- users = FakeFriend.list.keys.sample(n)
32
+ raise ArgumentError, "Can only gather 1 to 100 FakeFriends" unless n.between?(1, 100)
33
+ users = FakeFriend.all.keys.sample(n)
26
34
  users.map{ |username| FakeFriend.new(username) }
27
35
  end
28
36
 
@@ -30,7 +38,7 @@ module FakeFriends
30
38
  # Returns a FakeFriend object for a specific user in the user listing
31
39
  #
32
40
  # options - The Hash of options (default: {}):
33
- # :id - Integer - User's position in the user listing, 1 to 101
41
+ # :id - Integer - User's position in the user listing, 1 to 100
34
42
  # :username - String - User's Twitter username
35
43
  #
36
44
  # Examples
@@ -40,10 +48,10 @@ module FakeFriends
40
48
  #
41
49
  # Returns the requested FakeFriend object if found, else raises ArgumentError
42
50
  def self.find_by(options)
43
- if options[:id] && options[:id].between?(1, FakeFriend.list.count)
44
- username = FakeFriend.list.keys[options[:id]-1]
51
+ if options[:id] && options[:id].between?(1, FakeFriend.all.count)
52
+ username = FakeFriend.all.keys[options[:id]-1]
45
53
  FakeFriend.new(username)
46
- elsif options[:username] && FakeFriend.list.keys.include?(options[:username])
54
+ elsif options[:username] && FakeFriend.all.keys.include?(options[:username])
47
55
  FakeFriend.new(options[:username])
48
56
  else
49
57
  raise ArgumentError, "Requested user not found in library."
@@ -52,7 +60,7 @@ module FakeFriends
52
60
 
53
61
  # Public: FakeFriend.new(username)
54
62
  # Creates a FakeFriend object with attributes fetched from
55
- # the user listing defined in users.yml and accesses via FakeFriend.list
63
+ # the user listing defined in users.yml and accesses via FakeFriend.all
56
64
  #
57
65
  # username - String - a Twitter username found in the user listing
58
66
  #
@@ -61,14 +69,14 @@ module FakeFriends
61
69
  # FakeFriend.new('idiot')
62
70
  # # => #<FakeFriend:0x00000101348a80 @username="idiot"...>
63
71
  #
64
- # Returns a FakeFriend object with attributes populated from FakeFriend.list
72
+ # Returns a FakeFriend object with attributes populated from FakeFriend.all
65
73
  def initialize(username)
66
74
  @username = username
67
- @name = FakeFriend.list[username][:name]
68
- @location = FakeFriend.list[username][:location]
69
- @description = FakeFriend.list[username][:description]
70
- @url = FakeFriend.list[username][:url]
71
- @posts = FakeFriend.list[username][:posts]
75
+ @name = FakeFriend.all[username][:name]
76
+ @location = FakeFriend.all[username][:location]
77
+ @description = FakeFriend.all[username][:description]
78
+ @url = FakeFriend.all[username][:url]
79
+ @posts = FakeFriend.all[username][:posts]
72
80
  end
73
81
 
74
82
  # Public: returns a user's uiFaces url in the closest available size
@@ -82,18 +90,16 @@ module FakeFriends
82
90
  "https://s3.amazonaws.com/uifaces/faces/twitter/#{username}/#{size}.jpg"
83
91
  end
84
92
 
93
+
85
94
  private
86
- mydir = File.expand_path(File.dirname(__FILE__))
87
- libary_file = mydir + '/fake_friends/users.yml'
88
- @friends_list = File.open(libary_file, 'r'){|f| YAML.load(f) }
89
95
 
90
- # Private: FakeFriend.list
91
- #
92
- # Returns a class instance Hash variable holding the
93
- # user list defined in users.yml
94
- def self.list
95
- @friends_list
96
- end
96
+ def self.populate_friends_list
97
+ project_lib = File.expand_path(File.dirname(__FILE__))
98
+ library_file = "#{project_lib}/fake_friends/users.yml"
99
+ File.open(library_file, 'r'){|f| YAML.load(f) }
100
+ end
101
+
102
+ @friends_list = populate_friends_list
97
103
  end
98
104
 
99
105
  end
@@ -2,70 +2,69 @@ require 'spec_helper'
2
2
  include FakeFriends
3
3
 
4
4
  describe FakeFriend do
5
+ describe '::gather' do
6
+ context 'with valid input' do
7
+ let(:users) { FakeFriend.gather(5) }
5
8
 
6
- describe "::gather" do
7
- context "with valid input" do
8
- let(:users){ FakeFriend.gather(5) }
9
-
10
- it "returns an array of FakeFriends" do
9
+ it 'returns an array of FakeFriends' do
11
10
  expect(users).to be_an Array
12
11
  expect(users).to be_composed_of FakeFriend
13
12
  end
14
13
 
15
- it "returns the requested number of FakeFriends" do
14
+ it 'returns the requested number of FakeFriends' do
16
15
  expect(users.count).to be 5
17
16
  end
18
17
 
19
- it "does not return duplicates" do
18
+ it 'does not return duplicates' do
20
19
  expect(users.count).to be users.map(&:username).uniq.count
21
20
  end
22
21
  end
23
22
 
24
- context "with invalid input" do
25
- describe "with a negative number" do
23
+ context 'with invalid input' do
24
+ describe 'with a negative number' do
26
25
  it { expect { FakeFriend.gather(-1) }.to raise_error(ArgumentError) }
27
26
  end
28
- describe "with too high a number" do
29
- it { expect { FakeFriend.gather(102) }.to raise_error(ArgumentError) }
27
+ describe 'with too high a number' do
28
+ it { expect { FakeFriend.gather(101) }.to raise_error(ArgumentError) }
30
29
  end
31
30
  end
32
31
  end
33
32
 
33
+ describe '::find_by' do
34
+ context 'with valid input (by id)' do
35
+ let(:user) { FakeFriend.find_by(id: 1) }
34
36
 
35
- describe "::find_by" do
36
- context "with valid input (by id)" do
37
- let(:user){ FakeFriend.find_by(id: 1) }
38
-
39
- it "returns a FakeFriend" do
37
+ it 'returns a FakeFriend' do
40
38
  expect(user).to be_a FakeFriend
41
39
  end
42
40
 
43
- it "returns the correct FakeFriend" do
44
- expect(user.name).to eq("Visual Idiot")
41
+ it 'returns the correct FakeFriend' do
42
+ expect(user.name).to eq('Visual Idiot')
45
43
  end
46
44
  end
47
45
 
48
- context "with valid input (by username)" do
49
- let(:user){ FakeFriend.find_by(username: 'idiot') }
46
+ context 'with valid input (by username)' do
47
+ let(:user) { FakeFriend.find_by(username: 'idiot') }
50
48
 
51
- it "returns a FakeFriend" do
49
+ it 'returns a FakeFriend' do
52
50
  expect(user).to be_a FakeFriend
53
51
  end
54
52
 
55
- it "returns the correct FakeFriend" do
56
- expect(user.name).to eq("Visual Idiot")
53
+ it 'returns the correct FakeFriend' do
54
+ expect(user.name).to eq('Visual Idiot')
57
55
  end
58
56
  end
59
57
 
60
- context "with invalid input" do
61
- describe "with an invalid key" do
58
+ context 'with invalid input' do
59
+ describe 'with an invalid key' do
62
60
  it { expect { FakeFriend.find_by(age: 50) }.to raise_error(ArgumentError) }
63
61
  end
64
- describe "with an invalid id" do
65
- it { expect { FakeFriend.find_by(id: 102) }.to raise_error(ArgumentError) }
62
+ describe 'with an invalid id' do
63
+ it { expect { FakeFriend.find_by(id: -1) }.to raise_error(ArgumentError) }
64
+ it { expect { FakeFriend.find_by(id: 101) }.to raise_error(ArgumentError) }
66
65
  end
67
- describe "with an invalid username" do
68
- it { expect { FakeFriend.find_by(username: "invalid_username") }.to raise_error(ArgumentError) }
66
+ describe 'with an invalid username' do
67
+ it { expect { FakeFriend.find_by(username: 'invalid_username') }.to raise_error(ArgumentError) }
69
68
  end
70
69
  end
71
70
  end
data/spec/spec_helper.rb CHANGED
@@ -2,19 +2,17 @@ require 'fake_friends'
2
2
  require 'rspec/expectations'
3
3
 
4
4
  RSpec.configure do |config|
5
-
6
5
  config.expect_with :rspec do |c|
7
6
  c.syntax = :expect
8
7
  end
9
-
10
8
  end
11
9
 
12
10
  RSpec::Matchers.define :be_composed_of do |expected_type|
13
11
  match do |actual|
14
- actual.all?{|u| u.is_a? expected_type}
12
+ actual.all? { |u| u.is_a? expected_type }
15
13
  end
16
14
 
17
- failure_message_for_should do |actual|
15
+ failure_message do |actual|
18
16
  "expected #{actual.class} to be composed of #{expected_type}s"
19
17
  end
20
- end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_friends
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Romer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.6.0
19
+ version: '5.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.6.0
26
+ version: '5.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.14.1
33
+ version: '2.14'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.14.1
40
+ version: '2.14'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.5.2
47
+ version: '1.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.5.2
54
+ version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 10.1.0
61
+ version: '10.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 10.1.0
68
+ version: '10.1'
69
69
  description: A simple fake user generator
70
70
  email:
71
71
  - jacob.romer@icloud.com
@@ -88,7 +88,7 @@ files:
88
88
  - lib/fake_friends/version.rb
89
89
  - spec/fake_friends_spec.rb
90
90
  - spec/spec_helper.rb
91
- homepage: http://github.com/jmromer/FakeFriends
91
+ homepage: http://github.com/jkrmr/fake_friends
92
92
  licenses:
93
93
  - MIT
94
94
  metadata: {}
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.6
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Generates fake users with consistent attributes from public Twitter accounts
@@ -116,4 +116,3 @@ summary: Generates fake users with consistent attributes from public Twitter acc
116
116
  test_files:
117
117
  - spec/fake_friends_spec.rb
118
118
  - spec/spec_helper.rb
119
- has_rdoc: