|
11 | 11 | end |
12 | 12 | let(:writer_class) { writer.class } |
13 | 13 | let(:reader_class) { writer_class.format.reader} |
| 14 | + let(:format_class) { writer_class.format } |
14 | 15 |
|
15 | 16 | describe ".each" do |
16 | 17 | it "yields each writer" do |
|
63 | 64 | end |
64 | 65 |
|
65 | 66 | it "yields writer given file_name" do |
66 | | - writer_class.format.each do |f| |
67 | | - f.file_extensions.each_pair do |sym, content_type| |
68 | | - writer_mock = double("writer") |
69 | | - expect(writer_mock).to receive(:got_here) |
70 | | - expect(writer_class).to receive(:for).with(file_name: "#{@basename}.#{sym}").and_return(writer_class) |
71 | | - writer_class.open("#{@basename}.#{sym}") do |r| |
72 | | - expect(r).to be_a(RDF::Writer) |
73 | | - writer_mock.got_here |
74 | | - end |
75 | | - end |
76 | | - end |
77 | | - end |
78 | | - |
79 | | - it "yields writer given symbol" do |
80 | | - writer_class.format.each do |f| |
81 | | - sym = f.to_sym # Like RDF::NTriples::Format => :ntriples |
| 67 | + format_class.file_extensions.each_pair do |sym, content_type| |
82 | 68 | writer_mock = double("writer") |
83 | 69 | expect(writer_mock).to receive(:got_here) |
84 | | - expect(writer_class).to receive(:for).with(sym).and_return(writer_class) |
85 | | - writer_class.open("#{@basename}.#{sym}", format: sym) do |r| |
| 70 | + expect(writer_class).to receive(:for).with(file_name: "#{@basename}.#{sym}").and_return(writer_class) |
| 71 | + writer_class.open("#{@basename}.#{sym}") do |r| |
86 | 72 | expect(r).to be_a(RDF::Writer) |
87 | 73 | writer_mock.got_here |
88 | 74 | end |
89 | 75 | end |
90 | 76 | end |
91 | 77 |
|
| 78 | + it "yields writer given symbol" do |
| 79 | + sym = format_class.to_sym # Like RDF::NTriples::Format => :ntriples |
| 80 | + writer_mock = double("writer") |
| 81 | + expect(writer_mock).to receive(:got_here) |
| 82 | + expect(writer_class).to receive(:for).with(sym).and_return(writer_class) |
| 83 | + writer_class.open("#{@basename}.#{sym}", format: sym) do |r| |
| 84 | + expect(r).to be_a(RDF::Writer) |
| 85 | + writer_mock.got_here |
| 86 | + end |
| 87 | + end |
| 88 | + |
92 | 89 | it "yields writer given {file_name: file_name}" do |
93 | | - writer_class.format.each do |f| |
94 | | - f.file_extensions.each_pair do |sym, content_type| |
95 | | - writer_mock = double("writer") |
96 | | - expect(writer_mock).to receive(:got_here) |
97 | | - expect(writer_class).to receive(:for).with(file_name: "#{@basename}.#{sym}").and_return(writer_class) |
98 | | - writer_class.open("#{@basename}.#{sym}", file_name: "#{@basename}.#{sym}") do |r| |
99 | | - expect(r).to be_a(RDF::Writer) |
100 | | - writer_mock.got_here |
101 | | - end |
| 90 | + format_class.file_extensions.each_pair do |sym, content_type| |
| 91 | + writer_mock = double("writer") |
| 92 | + expect(writer_mock).to receive(:got_here) |
| 93 | + expect(writer_class).to receive(:for).with(file_name: "#{@basename}.#{sym}").and_return(writer_class) |
| 94 | + writer_class.open("#{@basename}.#{sym}", file_name: "#{@basename}.#{sym}") do |r| |
| 95 | + expect(r).to be_a(RDF::Writer) |
| 96 | + writer_mock.got_here |
102 | 97 | end |
103 | 98 | end |
104 | 99 | end |
105 | 100 |
|
106 | 101 | it "yields writer given {content_type: 'a/b'}" do |
107 | | - writer_class.format.each do |f| |
108 | | - f.content_types.each_pair do |content_type, formats| |
109 | | - writer_mock = double("writer") |
110 | | - expect(writer_mock).to receive(:got_here) |
111 | | - expect(writer_class).to receive(:for).with(content_type: content_type, file_name: @basename).and_return(writer_class) |
112 | | - writer_class.open(@basename, content_type: content_type) do |r| |
113 | | - expect(r).to be_a(RDF::Writer) |
114 | | - writer_mock.got_here |
115 | | - end |
| 102 | + format_class.content_types.each_pair do |content_type, formats| |
| 103 | + writer_mock = double("writer") |
| 104 | + expect(writer_mock).to receive(:got_here) |
| 105 | + expect(writer_class).to receive(:for).with(content_type: content_type, file_name: @basename).and_return(writer_class) |
| 106 | + writer_class.open(@basename, content_type: content_type) do |r| |
| 107 | + expect(r).to be_a(RDF::Writer) |
| 108 | + writer_mock.got_here |
116 | 109 | end |
117 | 110 | end |
118 | 111 | end |
|
0 commit comments