Skip to content

Commit

Permalink
request test for lyrics
Browse files Browse the repository at this point in the history
vcr gem to stub api requests. using Blind Faith in test suite because
they only have fourteen songs.
  • Loading branch information
alxndr committed Nov 29, 2013
1 parent a818e11 commit 784d867
Show file tree
Hide file tree
Showing 7 changed files with 24,220 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -27,6 +27,7 @@ end
group :development, :test do
gem 'brakeman', require: false
gem 'capybara'
gem 'colorize'
gem 'fuubar'
gem 'guard'
gem 'guard-rails'
Expand All @@ -39,13 +40,13 @@ group :development do
gem 'awesome_print'
gem 'better_errors'
gem 'binding_of_caller' # dependency of better_errors
gem 'colorize'
gem 'debugger'
gem 'guard'
end

group :test do
gem 'coveralls', require: false
gem 'vcr'
gem 'webmock'
end

2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -249,6 +249,7 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
vcr (2.8.0)
webmock (1.11.0)
addressable (>= 2.2.7)
crack (>= 0.3.2)
Expand Down Expand Up @@ -290,4 +291,5 @@ DEPENDENCIES
shoulda-matchers
turbolinks
uglifier (>= 1.3.0)
vcr
webmock
2 changes: 2 additions & 0 deletions app/models/artist.rb
Expand Up @@ -9,6 +9,7 @@ def random_lyric
if rand((@lyrics.length / 20) + 1).to_i == 0 # TODO make this more clear
new_lyrics = nil
until new_lyrics && new_lyrics.present?
# TODO don't die if we can't get more lyrics
new_lyrics = fetch_new_song_lyrics
end
@lyrics += new_lyrics
Expand Down Expand Up @@ -83,6 +84,7 @@ def sanitize_lyrics(lyrics_arr)
end

def pick_new_song
# TODO - return nil
raise 'no remaining songs (or none fetched)' unless (song_names - songs_fetched).present?

(song_names - songs_fetched).sample
Expand Down
14 changes: 6 additions & 8 deletions spec/features/lyrics_request_spec.rb
Expand Up @@ -3,15 +3,13 @@
describe 'lyrics' do

before do
stub_request(:get, 'http://lyrics.wikia.com/api.php?artist=fz&fmt=realjson&func=getArtist').
to_return(status: 200, body: "{artist: 'Frank Zappa'}", headers: {})

pending 'something up with stubbing'
visit '/text-from-lyrics-by/fz'
VCR.use_cassette 'artist_api_responses', record: :once do
visit '/text-from-lyrics-by/blind-faith/2/sentences'
end
end

it 'has a rel=canonical link' do
page.should have_selector 'link[rel=canonical][href=/text-from-lyrics-by/frank-zappa]'
page.source.should include '<link rel="canonical" href="/text-from-lyrics-by/blind-faith" />'
end

describe 'analytics' do
Expand All @@ -22,7 +20,7 @@

describe 'content' do
it 'includes lyrem' do
pending 'something up with stubbing'
pending 'how to verify random jumble against lyrics w/o touching db'
end

it 'asks you to type in your favorite band' do
Expand All @@ -31,4 +29,4 @@
end
end

end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -8,6 +8,7 @@
require 'rspec/autorun'
require 'webmock/rspec'
require 'capybara/rspec'
require Rails.root.join 'spec', 'support', 'vcr_setup.rb'

WebMock.disable_net_connect!(allow_localhost: true)

Expand Down

0 comments on commit 784d867

Please sign in to comment.