spec/reddit_spec.rb in popularity-0.1.1 vs spec/reddit_spec.rb in popularity-0.2.1
- old
+ new
@@ -25,23 +25,52 @@
it "should allow access to underlying results" do
expect(4687).to eq(subject.results.first.score)
end
context "json" do
- let(:json) { subject.to_json }
+ let(:json) { subject.as_json }
- it "should include post count in json" do
- expect(25).to eq(json["posts"])
+ it "should include post count in json" do
+ expect(json["posts"]).to eq(25)
end
- it "should comments in json" do
+ it "should have comments in json" do
expect(json["comments"]).to_not be_nil
end
- it "should score in json" do
+ it "should have score in json" do
expect(json["score"]).to_not be_nil
end
+
+ it "should have _results in json" do
+ expect(json["_results"]).to_not be_nil
+ end
+
+ context "results" do
+ let(:json_results) { subject.as_json["_results"] }
+
+ it "should equal number of results" do
+ expect(subject.results.size).to eq(json_results.size)
+ end
+
+ it "should contain the result urls" do
+ subject.results.each_with_index do |result, index|
+ json_result = json_results[index]
+
+ expect(json_result.keys.first).to eq(result.url)
+ end
+ end
+
+ it "should contain the correct values" do
+ subject.results.each_with_index do |result, index|
+ json_result = json_results[index]
+ expect(json_result.values.first["score"]).to eq(result.score)
+ expect(json_result.values.first["comments"]).to eq(result.comments)
+ expect(json_result.values.first["total"]).to eq(result.total)
+ end
+ end
+ end
end
context "unknown url" do
use_vcr_cassette "unknown-reddit-post"
subject {
@@ -63,27 +92,27 @@
it "should have correct score" do
expect(0).to eq(subject.score)
end
it "should have correct total" do
- expect(subject.total).to eq(subject.score + subject.comments)
+ expect(subject.total).to eq(subject.score + subject.comments + subject.posts)
end
context "json" do
- let(:json) { subject.to_json }
+ let(:json) { subject.as_json }
- it "should include post count in json" do
+ it "should include post count in json" do
expect(0).to eq(json["posts"])
end
- it "should comments in json" do
+ it "should comments in json" do
expect(0).to eq(json["comments"])
end
- it "should score in json" do
+ it "should score in json" do
expect(0).to eq(json["score"])
end
end
end
end
-end
\ No newline at end of file
+end