Closed m4tta closed 12 years ago
You can get the recent tracks, but the flag for nowplaying isn't parsed yet. If you need it fast, you could add it to the track.rb xml parsing. I will be able to add this on the weekend. Don't have time before that.
Awesome thanks.
If you add this for yourself till the weekend, I would be happy to see a pull request. Otherwise I will add those few lines by myself.
I was able to figure out how to add my change but I am too inexperienced with git and writing tests for my code to make a pull request :/
If you want to use this as a learning exercise, just go ahead. I would love to help you solving this task. The help-section here on github has a nice tutorial for forking and pulling. Forget the test for now, after you have done the changes without the test and send me the pull request, we will talk about adding the tests :) .
And if you need help with forking/pulling, feel free to ask.
Hey, great. You did it. One note: in ruby it's not common to use real tabs, it's 2 spaces for indention.
Do you want to add the test, too? If yes, I can give you a hand with that, aswel.
Sure. I am not sure where to begin though. Creating and running tests have always been confusing.
Running the tests is easy.
If you haven't done so, first run bundle
to be sure all needed gems are installed. After that start bundle exec rake test
, that will output something like this:
Finished tests in 4.014060s, 21.1756 tests/s, 86.6953 assertions/s.
That means all tests are okay.
Now to the (little) complicated part in the tests in the rockstar gem. Those tests work against an api. And because we don't want to have live calls against it (the data it returns can change and our tests would be ruined by that), I mock those api calls.
In test/fixtures/xml/track
you see a few files with xml results of the api. Grab the file "getinfo...." and copy it to a new name. Just change the Carrie to something different. Open the copy and add the attribute for the nowplaying to it.
Now we have the mock data. Now we need to test it.
In test/unit
you see that there is a test_track.rb
. In that is a method called test 'should be able to load track info'
. In that you add a new assert that checks that the nowplaying for that case is false, since it is not set in there, right?
Copy that method, create a new one that tests that nowplaying is set to true and use the other file for that. You have to copy the Track.new from the setup method for that and change it to the name you choosed for the file.
Ah, and by the way, another small thing from the naming conventions of ruby: word_is_seperated_by_underscore. So it should be now_playing instead of nowplaying.
Hope this helps you in finding your way through it.
There is a great guide about testing here : http://guides.rubyonrails.org . Make sure to read that. Testing is important ;)
Great that you actually tried it and completed this. Hope it was fun to try it.
The api provides a option to see if the recent track is NowPlaying http://www.last.fm/api/show?service=278
is there currently a way to do this?