Prohlížeč zdrojového kódu
spec/requests/examples_spec.rb
require "rails_helper"
RSpec.describe "Examples", type: :request do
describe "GET /examples" do
it "returns success" do
get examples_path
expect(response).to have_http_status(:success)
end
it "lists examples" do
get examples_path
expect(response.body).to include("Řadící algoritmy")
end
it "filters by tag" do
get examples_path(tag: "algoritmy")
expect(response.body).to include("Řadící algoritmy")
end
end
describe "GET /examples/:slug" do
it "returns success for valid slug" do
get example_path(slug: "sorting_algorithms")
expect(response).to have_http_status(:success)
end
it "shows the example title" do
get example_path(slug: "sorting_algorithms")
expect(response.body).to include("Řadící algoritmy")
end
it "shows syntax-highlighted code" do
get example_path(slug: "sorting_algorithms")
expect(response.body).to include('<span class="k">')
end
it "returns 404 for unknown slug" do
get example_path(slug: "nonexistent")
expect(response).to have_http_status(:not_found)
end
end
describe "POST /examples/:slug/run_scenario" do
it "runs a scenario and returns result" do
post run_scenario_example_path(slug: "sorting_algorithms"),
params: {
scenario_index: 0,
inputs: {
algorithm: "bubble_sort",
dataset: "[5, 3, 8, 1, 9, 2]"
}
}
expect(response).to have_http_status(:success)
expect(response.body).to include("bubble_sort")
end
it "rejects invalid scenario index" do
post run_scenario_example_path(slug: "sorting_algorithms"),
params: { scenario_index: 99, inputs: {} }
expect(response).to have_http_status(:unprocessable_content)
end
it "rejects tampered input values" do
post run_scenario_example_path(slug: "sorting_algorithms"),
params: {
scenario_index: 0,
inputs: {
algorithm: "evil_code",
dataset: "[5, 3, 8, 1, 9, 2]"
}
}
expect(response).to have_http_status(:unprocessable_content)
end
end
end