diff options
author | Gibheer <gibheer@gmail.com> | 2013-01-09 20:08:26 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2013-01-09 20:08:26 +0100 |
commit | ae0b32a58f01a111505198dd282b314e914c531a (patch) | |
tree | 00ea5f5ad5e4415c364f19aeda6df6ac93f54737 /spec | |
parent | d10862ce510f62bfb43222c861eb27676ca5f535 (diff) |
take strings for body
This makes the assignment for bodies easier when using plain Strings.
They get wrapped in an array as per rack definition.
For every other type, they have to implement each and get directly set
as body or have to be rendered to Strings first.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/zero/response/body_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/unit/zero/response/body_spec.rb b/spec/unit/zero/response/body_spec.rb index b70af04..0a40659 100644 --- a/spec/unit/zero/response/body_spec.rb +++ b/spec/unit/zero/response/body_spec.rb @@ -9,4 +9,31 @@ describe Zero::Response do subject.body.should eq([]) end end + + describe '#body=' do + let(:string) { "new body" } + let(:array) { ["new body"] } + let(:object_with_each) { {:a => "b" } } + let(:invalid_object) { 12345 } + + it "creates an array body for strings" do + subject.body = string + expect(subject.body).to eq(array) + end + + it "sets the body to the array" do + subject.body = array + expect(subject.body).to be(array) + end + + it "sets an object as string when responding to #each" do + subject.body = object_with_each + expect(subject.body).to be(object_with_each) + end + + it "raises an argument error for invalid input" do + expect{subject.body = invalid_object}.to raise_error( + ArgumentError, /invalid body/) + end + end end |