mbbx6spp-twitter4r 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGES +124 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +32 -0
  4. data/TODO +9 -0
  5. data/lib/twitter/client/account.rb +24 -0
  6. data/lib/twitter/client/auth.rb +27 -0
  7. data/lib/twitter/client/base.rb +87 -0
  8. data/lib/twitter/client/blocks.rb +35 -0
  9. data/lib/twitter/client/favorites.rb +53 -0
  10. data/lib/twitter/client/friendship.rb +35 -0
  11. data/lib/twitter/client/messaging.rb +79 -0
  12. data/lib/twitter/client/status.rb +46 -0
  13. data/lib/twitter/client/timeline.rb +72 -0
  14. data/lib/twitter/client/user.rb +65 -0
  15. data/lib/twitter/client.rb +21 -0
  16. data/lib/twitter/config.rb +71 -0
  17. data/lib/twitter/console.rb +28 -0
  18. data/lib/twitter/core.rb +137 -0
  19. data/lib/twitter/ext/stdlib.rb +51 -0
  20. data/lib/twitter/ext.rb +2 -0
  21. data/lib/twitter/extras.rb +39 -0
  22. data/lib/twitter/meta.rb +56 -0
  23. data/lib/twitter/model.rb +348 -0
  24. data/lib/twitter/rails.rb +92 -0
  25. data/lib/twitter/version.rb +19 -0
  26. data/lib/twitter.rb +31 -0
  27. data/spec/twitter/client/auth_spec.rb +34 -0
  28. data/spec/twitter/client/base_spec.rb +242 -0
  29. data/spec/twitter/client/blocks_spec.rb +76 -0
  30. data/spec/twitter/client/favorites_spec.rb +183 -0
  31. data/spec/twitter/client/friendship_spec.rb +76 -0
  32. data/spec/twitter/client/messaging_spec.rb +135 -0
  33. data/spec/twitter/client/status_spec.rb +92 -0
  34. data/spec/twitter/client/timeline_spec.rb +79 -0
  35. data/spec/twitter/client/user_spec.rb +203 -0
  36. data/spec/twitter/client_spec.rb +2 -0
  37. data/spec/twitter/config_spec.rb +86 -0
  38. data/spec/twitter/console_spec.rb +15 -0
  39. data/spec/twitter/core_spec.rb +127 -0
  40. data/spec/twitter/ext/stdlib_spec.rb +42 -0
  41. data/spec/twitter/extras_spec.rb +46 -0
  42. data/spec/twitter/meta_spec.rb +90 -0
  43. data/spec/twitter/model_spec.rb +464 -0
  44. data/spec/twitter/rails_spec.rb +110 -0
  45. data/spec/twitter/version_spec.rb +19 -0
  46. metadata +108 -0
@@ -0,0 +1,127 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe "Twitter::ClassUtilMixin mixed-in class" do
4
+ before(:each) do
5
+ class TestClass
6
+ include Twitter::ClassUtilMixin
7
+ attr_accessor :var1, :var2, :var3
8
+ end
9
+ @init_hash = { :var1 => 'val1', :var2 => 'val2', :var3 => 'val3' }
10
+ end
11
+
12
+ it "should have Twitter::ClassUtilMixin as an included module" do
13
+ TestClass.included_modules.member?(Twitter::ClassUtilMixin).should be(true)
14
+ end
15
+
16
+ it "should set attributes passed in the hash to TestClass.new" do
17
+ test = TestClass.new(@init_hash)
18
+ @init_hash.each do |key, val|
19
+ test.send(key).should eql(val)
20
+ end
21
+ end
22
+
23
+ it "should not set attributes passed in the hash that are not attributes in TestClass.new" do
24
+ test = nil
25
+ lambda { test = TestClass.new(@init_hash.merge(:var4 => 'val4')) }.should_not raise_error
26
+ test.respond_to?(:var4).should be(false)
27
+ end
28
+ end
29
+
30
+ describe "Twitter::RESTError#to_s" do
31
+ before(:each) do
32
+ @hash = { :code => 200, :message => 'OK', :uri => 'http://test.host/bla' }
33
+ @error = Twitter::RESTError.new(@hash)
34
+ @expected_message = "HTTP #{@hash[:code]}: #{@hash[:message]} at #{@hash[:uri]}"
35
+ end
36
+
37
+ it "should return @expected_message" do
38
+ @error.to_s.should eql(@expected_message)
39
+ end
40
+ end
41
+
42
+ describe "Twitter::Status#eql?" do
43
+ before(:each) do
44
+ @id = 34329594003
45
+ @attr_hash = { :text => 'Status', :id => @id,
46
+ :user => { :name => 'Tess',
47
+ :description => "Unfortunate D'Urberville",
48
+ :location => 'Dorset',
49
+ :url => nil,
50
+ :id => 34320304,
51
+ :screen_name => 'maiden_no_more' },
52
+ :created_at => 'Wed May 02 03:04:54 +0000 2007'}
53
+ @obj = Twitter::Status.new @attr_hash
54
+ @other = Twitter::Status.new @attr_hash
55
+ end
56
+
57
+ it "should return true when non-transient object attributes are eql?" do
58
+ @obj.should eql(@other)
59
+ end
60
+
61
+ it "should return false when not all non-transient object attributes are eql?" do
62
+ @other.created_at = Time.now.to_s
63
+ @obj.should_not eql(@other)
64
+ end
65
+
66
+ it "should return true when comparing same object to itself" do
67
+ @obj.should eql(@obj)
68
+ @other.should eql(@other)
69
+ end
70
+ end
71
+
72
+ describe "Twitter::User#eql?" do
73
+ before(:each) do
74
+ @attr_hash = { :name => 'Elizabeth Jane Newson-Henshard',
75
+ :description => "Wronged 'Daughter'",
76
+ :location => 'Casterbridge',
77
+ :url => nil,
78
+ :id => 6748302,
79
+ :screen_name => 'mayors_daughter_or_was_she?' }
80
+ @obj = Twitter::User.new @attr_hash
81
+ @other = Twitter::User.new @attr_hash
82
+ end
83
+
84
+ it "should return true when non-transient object attributes are eql?" do
85
+ @obj.should eql(@other)
86
+ end
87
+
88
+ it "should return false when not all non-transient object attributes are eql?" do
89
+ @other.id = 1
90
+ @obj.should_not eql(@other)
91
+ @obj.eql?(@other).should be(false)
92
+ end
93
+
94
+ it "should return true when comparing same object to itself" do
95
+ @obj.should eql(@obj)
96
+ @other.should eql(@other)
97
+ end
98
+ end
99
+
100
+ describe "Twitter::ClassUtilMixin#require_block" do
101
+ before(:each) do
102
+ class TestClass
103
+ include Twitter::ClassUtilMixin
104
+ end
105
+ @test_subject = TestClass.new
106
+ end
107
+
108
+ it "should respond to :require_block" do
109
+ @test_subject.should respond_to(:require_block)
110
+ end
111
+
112
+ it "should raise ArgumentError when block not given" do
113
+ lambda {
114
+ @test_subject.send(:require_block, false)
115
+ }.should raise_error(ArgumentError)
116
+ end
117
+
118
+ it "should not raise ArgumentError when block is given" do
119
+ lambda {
120
+ @test_subject.send(:require_block, true)
121
+ }.should_not raise_error(ArgumentError)
122
+ end
123
+
124
+ after(:each) do
125
+ @test_subject = nil
126
+ end
127
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Hash, "#to_http_str" do
4
+ before(:each) do
5
+ @http_params = {:id => 'otherlogin', :since_id => 3953743, :full_name => 'Lucy Cross'}
6
+ @id_regexp = Regexp.new("id=#{CGI.escape(@http_params[:id].to_s)}")
7
+ @since_id_regexp = Regexp.new("since_id=#{CGI.escape(@http_params[:since_id].to_s)}")
8
+ @full_name_regexp = Regexp.new("full_name=Lucy\\+Cross")
9
+ end
10
+
11
+ it "should generate expected URL encoded string" do
12
+ http_str = @http_params.to_http_str
13
+ http_str.should match(@id_regexp)
14
+ http_str.should match(@since_id_regexp)
15
+ http_str.should match(@full_name_regexp)
16
+ end
17
+
18
+ after(:each) do
19
+ @http_params = nil
20
+ @id_kv_str, @since_id_kv_str, @full_name_kv_str = nil
21
+ end
22
+ end
23
+
24
+ describe Time, "#to_s" do
25
+ before(:each) do
26
+ @time = Time.now
27
+ @expected_string = @time.rfc2822
28
+ end
29
+
30
+ it "should output RFC2822 compliant string" do
31
+ time_string = @time.to_s
32
+ time_string.should eql(@expected_string)
33
+ end
34
+
35
+ it "should respond to #old_to_s" do
36
+ @time.should respond_to(:old_to_s)
37
+ end
38
+
39
+ after(:each) do
40
+ nilize(@time, @expected_string)
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, "#featured(:users)" do
4
+ before(:each) do
5
+ @twitter = client_context
6
+ @uris = Twitter::Client.class_eval("@@FEATURED_URIS")
7
+ @request = mas_net_http_get(:basic_auth => nil)
8
+ @response = mas_net_http_response(:success)
9
+ @connection = mas_net_http(@response)
10
+ Net::HTTP.stub!(:new).and_return(@connection)
11
+ @users = [
12
+ Twitter::User.new(:screen_name => 'twitter4r'),
13
+ Twitter::User.new(:screen_name => 'dictionary'),
14
+ ]
15
+ Twitter::User.stub!(:unmarshal).and_return(@users)
16
+ end
17
+
18
+ it "should create expected HTTP GET request" do
19
+ @twitter.should_receive(:create_http_get_request).with(@uris[:users]).and_return(@request)
20
+ @twitter.featured(:users)
21
+ end
22
+
23
+ it "should bless Twitter::User models returned" do
24
+ @twitter.should_receive(:bless_models).with(@users).and_return(@users)
25
+ @twitter.featured(:users)
26
+ end
27
+
28
+ after(:each) do
29
+ nilize(@twitter, @uris, @request, @response, @connection)
30
+ end
31
+ end
32
+
33
+ describe Twitter::User, ".featured" do
34
+ before(:each) do
35
+ @twitter = client_context
36
+ end
37
+
38
+ it "should delegate #featured(:users) message to given client context" do
39
+ @twitter.should_receive(:featured).with(:users).and_return([])
40
+ Twitter::User.featured(@twitter)
41
+ end
42
+
43
+ after(:each) do
44
+ nilize(@twitter)
45
+ end
46
+ end
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ def glob_files(*path_elements)
4
+ Dir.glob(File.join(*path_elements))
5
+ end
6
+
7
+ def load_erb_yaml(path, context)
8
+ ryaml = ERB.new(File.read(path), 0)
9
+ YAML.load(ryaml.result(context))
10
+ end
11
+
12
+ module ERBMetaMixin
13
+ # Needed to make the YAML load work...
14
+ def project_files
15
+ glob_files(@root_dir, 'lib', '**/*.rb')
16
+ end
17
+
18
+ # Needed to make the YAML load work...
19
+ def spec_files
20
+ glob_files(@root_dir, 'spec', '**/*_spec.rb')
21
+ end
22
+ end
23
+
24
+ describe "Twitter::Meta cache policy" do
25
+ include ERBMetaMixin
26
+ before(:each) do
27
+ @root_dir = project_root_dir
28
+ @meta = Twitter::Meta.new(@root_dir)
29
+ @expected_pkg_info = load_erb_yaml(File.join(@root_dir, 'pkg-info.yml'), binding)
30
+ @expected_project_files = project_files
31
+ @expected_spec_files = spec_files
32
+ end
33
+
34
+ it "should store value returned from project_files in @project_files after first glob" do
35
+ @meta.instance_eval("@project_files").should eql(nil)
36
+ @meta.project_files
37
+ @meta.instance_eval("@project_files").should eql(@expected_project_files)
38
+ @meta.project_files
39
+ @meta.instance_eval("@project_files").should eql(@expected_project_files)
40
+ end
41
+
42
+ it "should store value returned from spec_files in @spec_files after first glob" do
43
+ @meta.instance_eval("@spec_files").should eql(nil)
44
+ @meta.spec_files
45
+ @meta.instance_eval("@spec_files").should eql(@expected_spec_files)
46
+ @meta.spec_files
47
+ @meta.instance_eval("@spec_files").should eql(@expected_spec_files)
48
+ end
49
+ end
50
+
51
+ describe "Twitter::Meta" do
52
+ include ERBMetaMixin
53
+ before(:each) do
54
+ @root_dir = project_root_dir
55
+ @meta = Twitter::Meta.new(@root_dir)
56
+ @expected_yaml_hash = load_erb_yaml(File.join(@root_dir, 'pkg-info.yml'), binding)
57
+ @expected_project_files = project_files
58
+ @expected_spec_files = spec_files
59
+ end
60
+
61
+ it "should load and return YAML file into Hash object upon #pkg_info call" do
62
+ yaml_hash = @meta.pkg_info
63
+ yaml_hash.should.eql? @expected_yaml_hash
64
+ end
65
+
66
+ it "should return the embedded hash responding to key 'spec' of #pkg_info call upon #spec_info call" do
67
+ yaml_hash = @meta.spec_info
68
+ yaml_hash.should.eql? @expected_yaml_hash['spec']
69
+ end
70
+
71
+ it "should return list of files matching ROOT_DIR/lib/**/*.rb upon #project_files call" do
72
+ project_files = @meta.project_files
73
+ project_files.should.eql? @expected_project_files
74
+ end
75
+
76
+ it "should return list of files matching ROOT_DIR/spec/**/*.rb upon #spec_files call" do
77
+ spec_files = @meta.spec_files
78
+ spec_files.should.eql? @expected_spec_files
79
+ end
80
+
81
+ it "should return Gem specification based on YAML file contents and #project_files and #spec_files return values" do
82
+ spec = @meta.gem_spec
83
+ expected_spec_hash = @expected_yaml_hash['spec']
84
+ expected_spec_hash.each do |key, val|
85
+ unless val.is_a?(Hash)
86
+ spec.send(key).should.eql? expected_spec_hash[key]
87
+ end
88
+ end
89
+ end
90
+ end