Testing and Development - AlyBadawy/Securial GitHub Wiki
🧪 Testing Securial
Securial uses RSpec for its test suite and is fully instrumented for code coverage via SimpleCov. This page explains how to set up and run tests locally.
⚙️ Setup
To begin testing Securial:
-
Clone the repo:
$ git clone [email protected]:AlyBadawy/Securial.git $ cd Securial
-
Install dependencies:
$ bundle install
▶️ Running the Test Suite
Use the provided bin/test script to run the full test suite:
$ bin/test
This command will:
- Prepare the test database automatically
- Run all specs using RSpec
📊 Code Coverage
Securial uses SimpleCov to track code coverage. After running the tests, a detailed HTML report is available:
$ open coverage/index.html
🧪 Writing Specs
RSpec specs are organized under the spec/ directory. You can find and extend the following types of specs:
Directory | Purpose |
---|---|
spec/models/ | Unit specs for ActiveRecord models |
spec/controllers/ | Specs for internal engine controllers |
spec/requests/ | Integration tests for API endpoints |
spec/mailers/ | Specs for mailer logic and delivery |
spec/routing/ | Route specs to test routing behavior |
spec/securial/ | Engine-specific tests |
spec/support/ | Shared helpers and config |
[!IMPORTANT] Securial does not use fixtures. It uses FactoryBot for creating test data.
[!TIP] The FactoryBot factories are located at
/lib/securial/factories
Example Request Spec
RSpec.describe "POST /securial/sessions/login", type: :request do
it "logs in successfully with valid credentials" do
post "/securial/sessions/login", params: { username: "admin", password: "secret" }, as: :json
expect(response).to have_http_status(:success)
expect(JSON.parse(response.body)).to include("access_token")
end
end
🧼 Running Individual Specs
To run a specific file:
$ bin/test spec/requests/sessions_spec.rb
To run a single test within a file:
$ bin/test spec/requests/sessions_spec.rb:15
🏗 Dummy App for Testing
Securial uses a dummy Rails app located in spec/dummy/ to simulate a host application. This is useful for testing engine integration in a real app context.
🧩 Testing Customizations
If you're extending or overriding parts of Securial, make sure to:
- Write request specs for custom endpoints
- Add model specs for new business logic
- Cover JSON views and serializers
- Use the dummy app to simulate real-world use cases
Happy testing! ✅