Skip to content

Commit

Permalink
Review: split big test into smaller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTowers committed Mar 12, 2021
1 parent c061010 commit bfbd1d7
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
RSpec.describe GovukTechDocs::TechDocsHTMLRenderer do
let(:app) { double("app") }
let(:context) { double("context") }
let(:processor) {
allow(context).to receive(:app) { app }
allow(app).to receive(:api)
Redcarpet::Markdown.new(described_class.new(context: context), tables: true)
}

describe "#render a table" do
it "renders tables with row headings" do
app = double("app")
context = double("context")
allow(context).to receive(:app) { app }
allow(app).to receive(:api)
markdown_table = <<~MARKDOWN
| A | B |
|------|---|
|# C | D |
| E | F |
|# *G* | H |
MARKDOWN

processor = Redcarpet::Markdown.new(described_class.new(context: context), tables: true)
output = processor.render <<~MARKDOWN
| A | B |
|------|---|
|# C | D |
| E | F |
|# *G* | H |
MARKDOWN
it "treats cells in the heading row as headings" do
output = processor.render markdown_table

# Cells in the heading row should be treated as headings
expect(output).to include("<th>A</th>")
expect(output).to include("<th>B</th>")
end

# Cells starting with `#` should be treated as row headings
it "treats cells starting with # as row headings" do
output = processor.render markdown_table
expect(output).to include('<th scope="row">C</th>')
end

# Cells starting with `#` with more complex markup should be treated as row headings
it "treats cells starting with # with more complex markup as row headings" do
output = processor.render markdown_table
expect(output).to match(/<th scope="row"><em>G<\/em>\s*<\/th>/)
end

# Other cells should be treated as ordinary cells
it "treats other cells as ordinary cells" do
output = processor.render markdown_table
expect(output).to include("<td>D</td>")
expect(output).to include("<td>E</td>")
expect(output).to include("<td>F</td>")
Expand Down

0 comments on commit bfbd1d7

Please sign in to comment.