-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
panda level #14
base: master
Are you sure you want to change the base?
panda level #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,48 @@ | |
|
||
describe Api do | ||
|
||
let(:movie) { Api.search_by_title("Forrest Gump") } | ||
context "valid movie title" do | ||
|
||
before do | ||
Api.stub(:get_url_as_json) { JSON.parse(File.read("spec/fixtures/forrest.json")) } | ||
end | ||
let(:movie) { Api.search_by_title("Forrest Gump") } | ||
|
||
it "should search for movies" do | ||
movie.title.should eq("Forrest Gump") | ||
end | ||
before do | ||
expect { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not add the expect here in the before block. The before block is adding this test to every example. I do think having this in the before makes sense, because you want every time it executes Api.stub(:get_url_as_json) { JSON.parse(File.read("spec/fixtures/forrest.json")) |
||
Api.stub(:get_url_as_json) { JSON.parse(File.read("spec/fixtures/forrest.json")) } | ||
}.to_not raise_error | ||
end | ||
|
||
it "should return the score" do | ||
movie.score.should eq(71) | ||
end | ||
it "should search for movies" do | ||
movie.title.should eq("Forrest Gump") | ||
end | ||
|
||
it "should return the score" do | ||
movie.score.should eq(71) | ||
end | ||
|
||
it "should return the id" do | ||
movie.id.should eq(10036) | ||
end | ||
|
||
it "should return the year" do | ||
movie.year.should eq(1994) | ||
end | ||
|
||
it "should return the id" do | ||
movie.id.should eq(10036) | ||
end | ||
|
||
it "should return the year" do | ||
movie.year.should eq(1994) | ||
context "invalid movie title" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how I'd write this. No problem with the way you did, but this might be more readable. context "invalid movie title" do
it "should return :no_movie_found" do
Api.stub(:get_url_as_json) { JSON.parse(File.read("spec/fixtures/invalid.json"))
Api.search_by_title("hgh").should eq(:no_movie_found)
end
end |
||
let(:movie) { Api.search_by_title("hgh") } | ||
|
||
before do | ||
expect { | ||
Api.stub(:get_url_as_json) { JSON.parse(File.read("spec/fixtures/invalid.json")) } | ||
}.to_not raise_error | ||
end | ||
|
||
it "should return :no_movie_found" do | ||
movie.should eq(:no_movie_found) | ||
end | ||
|
||
end | ||
|
||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you are rescuing the entire
search_by_title
method, where no matter what exception is raised, you're showing "no_movie_found". That's not REALLY the case though. For example, if the API is down or broken, you still want people to be able to find their "Caddyshack"