Skip to content

Support rspec #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Scripts/commands/RailsAlternateFile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const SETTINGS = require("../settings")

exports.RailsAlternateFile = class RailsAlternateFile {
constructor() {
// FIXME: Handle running the command while something else than a file is active (like a terminal)
Expand All @@ -7,23 +9,25 @@ exports.RailsAlternateFile = class RailsAlternateFile {

// TODO: Refactor and improve code quality
alternate() {
var testType = (SETTINGS.general.alternateFileType == "rspec" ? "spec" : "test");

// If neither app nor test are found in the path, can't find associated file
if (this.splitPath.indexOf("app") === -1 && this.splitPath.indexOf("test") === -1) {
if (this.splitPath.indexOf("app") === -1 && this.splitPath.indexOf(testType) === -1) {
this.showError("Couldn't find alternate files. Does the workspace contain a Rails project?")
return
}

const rootIndex = this.splitPath.indexOf("app") === -1 ? this.splitPath.indexOf("test") : this.splitPath.indexOf("app")
const rootIndex = this.splitPath.indexOf("app") === -1 ? this.splitPath.indexOf(testType) : this.splitPath.indexOf("app")
const rootDir = this.splitPath[rootIndex]
const associatedDir = rootDir === "app" ? "test" : "app"
const associatedDir = rootDir === "app" ? testType : "app"

const currentFileName = this.splitPath[this.splitPath.length - 1]
let associatedFileName

if (associatedDir === "test") {
associatedFileName = currentFileName.slice(0, -3).concat("_test.rb")
if (associatedDir === testType) {
associatedFileName = currentFileName.slice(0, -3).concat("_${testType}.rb")
} else {
associatedFileName = currentFileName.replace("_test", "")
associatedFileName = currentFileName.replace("_${testType}", "")
}

let newSplitPath = this.splitPath
Expand Down
2 changes: 2 additions & 0 deletions Scripts/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// EXTENSION
const { statusNotifications } = require("./settings/general/statusNotifications")
const { alternateFileType } = require("./settings/general/alternateFileType")
// SOLARGRAPH
const { autoFormat } = require("./settings/solargraph/autoFormat")
const { bundlerPath } = require("./settings/solargraph/bundlerPath")
Expand All @@ -23,6 +24,7 @@ const { autocorrectDisableUncorrectable } = require("./settings/rubocop/autocorr

module.exports = {
statusNotifications,
alternateFileType,
solargraph: {
autoFormat,
bundlerPath,
Expand Down
32 changes: 32 additions & 0 deletions Scripts/settings/general/alternateFileType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function reload() {
nova.commands.invoke("tommasonegri.rails.commands.reload")
}

nova.config.onDidChange("tommasonegri.rails.config.general.alternateFileType", reload)
nova.workspace.config.onDidChange("tommasonegri.rails.config.general.alternateFileType", reload)

function getExtensionSetting() {
return nova.config.get("tommasonegri.rails.config.general.alternateFileType", "boolean")
}

function getWorkspaceSetting() {
const str = nova.workspace.config.get("tommasonegri.rails.config.general.alternateFileType", "string")

switch (str) {
case "Global Default":
return null
case "minitest":
return "minitest"
case "rspec":
return "rspec"
default:
return null
}
}

exports.statusNotialternateFileTypefications = function() {
const workspaceConfig = getWorkspaceSetting()
const extensionConfig = getExtensionSetting()

return workspaceConfig === null ? extensionConfig : workspaceConfig
}
18 changes: 18 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@
"type": "boolean",
"default": true
},
{
"key": "tommasonegri.rails.config.general.alternateFileType",
"title": "Alternate File type",
"description": "Select whether 'Open Alternate File' should use minitest or rspec.",
"type": "enum",
"values": ["minitest", "rspec"],
"radio": false,
"default": "minitest"
},
{
"title": "Solargraph",
"description": "Solargraph is a Ruby language server and suite of static analysis tools. The language server provides intellisense, autocompletion, diagnostics, and other language features for editors and IDEs with language client capabilities. The static analysis tools check code for type safety.",
Expand Down Expand Up @@ -557,6 +566,15 @@
"radio": false,
"default": "Global Default"
},
{
"key": "tommasonegri.rails.config.general.alternateFileType",
"title": "Alternate File type",
"description": "Select whether 'Open Alternate File' should use minitest or rspec.",
"type": "enum",
"values": ["Global Default", "minitest", "rspec"],
"radio": false,
"default": "Global Default"
},
{
"title": "Solargraph settings",
"description": "Solargraph is a Ruby language server and suite of static analysis tools. The language server provides intellisense, autocompletion, diagnostics, and other language features for editors and IDEs with language client capabilities. The static analysis tools check code for type safety.",
Expand Down