{"id":14991257,"url":"https://github.com/olimorris/neotest-rspec","last_synced_at":"2025-04-05T07:02:55.791Z","repository":{"id":36994361,"uuid":"502314354","full_name":"olimorris/neotest-rspec","owner":"olimorris","description":"🧪 Neotest adapter for RSpec. Works in Docker containers too","archived":false,"fork":false,"pushed_at":"2025-03-12T22:18:12.000Z","size":117,"stargazers_count":97,"open_issues_count":2,"forks_count":29,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T16:21:32.118Z","etag":null,"topics":["neotest","neovim","neovim-plugin","nvim","nvim-plugin","rspec","ruby"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olimorris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-11T10:14:23.000Z","updated_at":"2025-03-15T11:37:10.000Z","dependencies_parsed_at":"2023-02-18T15:30:32.317Z","dependency_job_id":"eb46152c-fc08-4351-ad04-3d3954380681","html_url":"https://github.com/olimorris/neotest-rspec","commit_stats":{"total_commits":122,"total_committers":19,"mean_commits":6.421052631578948,"dds":"0.28688524590163933","last_synced_commit":"a7910019d723a214d95400dd59317cf15561dba1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olimorris%2Fneotest-rspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olimorris%2Fneotest-rspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olimorris%2Fneotest-rspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olimorris%2Fneotest-rspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olimorris","download_url":"https://codeload.github.com/olimorris/neotest-rspec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299831,"owners_count":20916190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["neotest","neovim","neovim-plugin","nvim","nvim-plugin","rspec","ruby"],"created_at":"2024-09-24T14:22:01.965Z","updated_at":"2025-04-05T07:02:55.774Z","avatar_url":"https://github.com/olimorris.png","language":"Lua","funding_links":[],"categories":["Lua"],"sub_categories":[],"readme":"# neotest-rspec\n\n\u003c!-- [![Tests](https://github.com/olimorris/neotest-rspec/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/olimorris/neotest-rspec/actions/workflows/ci.yml) --\u003e\n\nThis plugin provides an [RSpec](https://rspec.info) adapter for the [Neotest](https://github.com/nvim-neotest/neotest) framework.\n\n\u003cimg width=\"1502\" alt=\"Neotest and RSpec\" src=\"https://user-images.githubusercontent.com/9512444/174159395-d4dc5e1e-9c3c-449f-b235-6fc8835fed5b.png\"\u003e\n\n## :package: Installation\n\nInstall with the package manager of your choice:\n\n**Lazy**\n\n```lua\n{\n  \"nvim-neotest/neotest\",\n  lazy = true,\n  dependencies = {\n    ...,\n    \"olimorris/neotest-rspec\",\n  },\n  config = function()\n    require(\"neotest\").setup({\n      ...,\n      adapters = {\n        require(\"neotest-rspec\")\n      },\n    })\n  end\n}\n```\n\n**Packer**\n\n```lua\nuse({\n  \"nvim-neotest/neotest\",\n  requires = {\n    ...,\n    \"olimorris/neotest-rspec\",\n  },\n  config = function()\n    require(\"neotest\").setup({\n      ...,\n      adapters = {\n        require(\"neotest-rspec\"),\n      }\n    })\n  end\n})\n```\n\n## :wrench: Configuration\n\n### Default configuration\n\n\u003e [!NOTE]\n\u003e You only need to the call the `setup` function if you wish to change any of the defaults\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to see the default configuration\u003c/summary\u003e\n\n```lua\nadapters = {\n  require(\"neotest-rspec\")({\n    rspec_cmd = function()\n      return vim.tbl_flatten({\n        \"bundle\",\n        \"exec\",\n        \"rspec\",\n      })\n    end,\n    root_files = { \"Gemfile\", \".rspec\", \".gitignore\" },\n    filter_dirs = { \".git\", \"node_modules\" },\n    transform_spec_path = function(path)\n      return path\n    end,\n    results_path = function()\n      return async.fn.tempname()\n    end,\n    formatter = function()\n      return \"NeotestFormatter\"\n    end\n  }),\n}\n```\n\n\u003c/details\u003e\n\n### The test command\n\nThe command used to run tests can be changed via the `rspec_cmd` option:\n\n```lua\nrequire(\"neotest-rspec\")({\n  rspec_cmd = function()\n    return vim.tbl_flatten({\n      \"bundle\",\n      \"exec\",\n      \"rspec\",\n    })\n  end\n})\n```\n\nOne issue you can run into is when you use generated tests:\n\n```ruby\nRSpec.describe SomeClass do\n  describe \"some feature\" do\n    FIXTURES.each do |method, path|\n      it \"does something with the #{method} and #{path}\" do\n        # ...\n      end\n    end\n  end\nend\n```\n\nThe test will show as passing if any one of the tests pass instead of if all of\nthem pass. You can change the test command to use `--fail-fast` to fix this.\nHowever now your other tests will all fail if even a single test fails.\n\nTo solve this you can customize your command depending on the type of test you\nare running by using the optional positional argument `position_type`\n\n\n```lua\nrequire(\"neotest-rspec\")({\n  -- Optionally your function can take a position_type which is one of:\n  -- - \"file\"\n  -- - \"test\"\n  -- - \"dir\"\n  rspec_cmd = function(position_type)\n    if position_type == \"test\" then\n      return vim.tbl_flatten({\n        \"bundle\",\n        \"exec\",\n        \"rspec\",\n        \"--fail-fast\"\n      })\n    else\n      return vim.tbl_flatten({\n        \"bundle\",\n        \"exec\",\n        \"rspec\",\n      })\n    end\n end\n})\n```\n\nNow when you run your tests from a single test it will fail fast and show the\ncorrect error on your generated tests. When you run the whole file it won't fail\nfast and a single error won't cause all your other tests to fail.\n\n### Setting the root directory\n\nFor Neotest adapters to work, they need to define a project root whereby the process of discovering tests can take place. By default, the adapter looks for a `Gemfile`, `.rspec` or `.gitignore` file. These can be changed with:\n\n```lua\nrequire(\"neotest-rspec\")({\n  root_files = { \"README.md\" }\n})\n```\n\nYou can even set `root_files` with a function which returns a table:\n\n```lua\nrequire(\"neotest-rspec\")({\n  root_files = function() return { \"README.md\" } end\n})\n```\n\n### Filtering directories\n\nBy default, the adapter will search for `_spec.rb` files in all dirs in the root with the exception of `node_modules` and `.git`. You can change this with:\n\n```lua\nrequire(\"neotest-rspec\")({\n  filter_dirs = { \"my_custom_dir\" }\n})\n```\n\nYou can even set `filter_dirs` with a function which returns a table:\n\n```lua\nrequire(\"neotest-rspec\")({\n  filter_dirs = function() return { \"my_custom_dir\" } end\n})\n```\n\n### Running tests in a Docker container\n\nThe following configuration overrides `rspec_cmd` to run a Docker container (using `docker-compose`) and overrides `transform_spec_path` to pass the spec file as a relative path instead of an absolute path to RSpec. The `results_path` needs to be set to a location which is available to both the container and the host. Additionally, to avoid using a custom formatter, you need to specify `formatter = \"json\"`.\n\n```lua\nrequire(\"neotest\").setup({\n  adapters = {\n    require(\"neotest-rspec\")({\n      rspec_cmd = function()\n        return vim.tbl_flatten({\n          \"docker\",\n          \"compose\",\n          \"exec\",\n          \"-i\",\n          \"-w\", \"/app\",\n          \"-e\", \"RAILS_ENV=test\",\n          \"app\",\n          \"bundle\",\n          \"exec\",\n          \"rspec\"\n        })\n      end,\n\n      transform_spec_path = function(path)\n        local prefix = require('neotest-rspec').root(path)\n        return string.sub(path, string.len(prefix) + 2, -1)\n      end,\n\n      results_path = \"tmp/rspec.output\",\n      formatter = \"json\"\n    })\n  }\n})\n```\n\nAlternatively, you can accomplish this using a shell script as your RSpec command. See [this comment](https://github.com/nvim-neotest/neotest/issues/89#issuecomment-1338141432) for an example.\n\n## :rocket: Usage\n\n\u003e [!IMPORTANT]\n\u003e In order for the adapter to work, your RSpec tests must end in `_spec.rb`\n\n#### Test single function\n\nTo test a single test, hover over the test and run `require(\"neotest\").run.run()`\n\n#### Test file\n\nTo test a file run `require(\"neotest\").run.run(vim.fn.expand(\"%\"))`\n\n#### Test directory\n\nTo test a directory run `require(\"neotest\").run.run(\"path/to/directory\")`\n\n#### Test suite\n\nTo test the full test suite run `require(\"neotest\").run.run(\"path/to/root_project\")`\ne.g. `require(\"neotest\").run.run(vim.fn.getcwd())`, presuming that vim's directory is the same as the project root.\n\n#### Debug test\n\nIn order to enable DAP for a test or test suite, ensure that [nvim-dap](https://github.com/mfussenegger/nvim-dap) and [nvim-dap-ruby](https://github.com/suketa/nvim-dap-ruby) are installed and follow the [strategies](https://github.com/nvim-neotest/neotest?tab=readme-ov-file#strategies) docs. An example snippet can be found below.\n\n```lua\nrequire(\"neotest\").run.run({ strategy = \"dap\" })\n```\n\nThis will run the closest test under DAP.\n\n## :gift: Contributing\n\nThis project is maintained by the Neovim Ruby community. Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example spec that can be tested.\n\nTo trigger the tests for the adapter, run:\n\n```sh\nmake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folimorris%2Fneotest-rspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folimorris%2Fneotest-rspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folimorris%2Fneotest-rspec/lists"}