मैं ट्विटर मणि का उपयोग कर एक टेस्ट ऐप लिख रहा हूं और मैं एकीकरण परीक्षण लिखना चाहता हूं लेकिन मैं यह नहीं समझ सकता कि ट्विटर नामस्थान में ऑब्जेक्ट्स का नकल कैसे करें।रूबी में किसी तृतीय पक्ष ऑब्जेक्ट को नकल करने का सबसे अच्छा तरीका क्या है?
1) testing oauth twitter
Failure/Error: login_with_oauth
Twitter::Error::Unauthorized:
GET https://api.twitter.com/1/account/verify_credentials.json: 401: Invalid/expired Token
# ./app/models/user.rb:40:in `build_twitter'
# ./app/models/user.rb:16:in `build_authentication'
# ./app/controllers/authentications_controller.rb:47:in `create'
# ./spec/support/integration_spec_helper.rb:3:in `login_with_oauth'
# ./spec/integration/twit_test.rb:16:in `block (2 levels) in <top (required)>'
: मैं इस त्रुटि मिल रही है,
feature 'testing oauth' do
before(:each) do
@twitter = double("Twitter")
@twitter.stub!(:configure).and_return true
@client = double("Twitter::Client")
@client.stub!(:current_user).and_return(@user)
@user = double("Twitter::User")
@user.stub!(:name).and_return("Tester")
end
scenario 'twitter' do
visit root_path
login_with_oauth
page.should have_content("Pages#home")
end
end
लेकिन: यहाँ समारोह है कि मैं परीक्षण करना चाहते हैं:
def build_twitter(omniauth)
Twitter.configure do |config|
config.consumer_key = TWITTER_KEY
config.consumer_secret = TWITTER_SECRET
config.oauth_token = omniauth['credentials']['token']
config.oauth_token_secret = omniauth['credentials']['secret']
end
client = Twitter::Client.new
user = client.current_user
self.name = user.name
end
और यहाँ rspec परीक्षण है कि मैं लिखने के लिए कोशिश कर रहा हूँ है
ऊपर दिए गए मिक्स rspec का उपयोग कर रहे हैं लेकिन मैं भी मोचा की कोशिश करने के लिए खुला हूं। किसी भी तरह की सहायता का स्वागत किया जाएगा।
ठीक है, मैं इसे हर किसी की मदद के लिए धन्यवाद देने में कामयाब रहा। यहाँ अंतिम परीक्षण है:
feature 'testing oauth' do
before(:each) do
@client = double("Twitter::Client")
@user = double("Twitter::User")
Twitter.stub!(:configure).and_return true
Twitter::Client.stub!(:new).and_return(@client)
@client.stub!(:current_user).and_return(@user)
@user.stub!(:name).and_return("Tester")
end
scenario 'twitter' do
visit root_path
login_with_oauth
page.should have_content("Pages#home")
end
end
चाल पता लगाना था कि मैं असली वस्तुओं पर :configure
और :new
ठूंठ करने की जरूरत है और एक dobuled वस्तु दृष्टान्त पर :current_user
और :name
ठूंठ।
हाँ! धन्यवाद। आप बिल्कुल सही हैं कि मॉडल पर एक विधि को दबाकर और दोगुना हुआ एक उदाहरण छीनने के बीच मुझे अंतर याद आ रहा था। इसके लिए धन्यवाद मैं इसे समझने में सक्षम था। मैं इस सवाल को संपादित करने के लिए संपादित करूंगा कि मैंने अंत में इसे कैसे हल किया। – spinlock